Print: The command print(“ ”)
is used to output the string/text contained within the parentheses to the console or standard output. This is fundamental for displaying information to users or for debugging.
Comments: Comments are marked by a #
symbol, allowing programmers to leave notes for themselves or others about what specific sections of code involve. This helps in documenting the code for better understanding and maintenance.
Data Types: There are several basic data types in programming:
String: A sequence of characters, typically used to represent text (e.g., "Hello World"
). Strings can include letters, numbers, and symbols.
Integer: A whole number without a fraction (e.g., 42
).
Float: A number that includes a decimal point, allowing for values below or above one (e.g., 3.14
).
Boolean: A logical data type that can take the value True
or False
, often used for conditional statements.
Variable: A storage location identified by a name (e.g., x
, y
) that can hold different values over time. It acts like a box where you can put a value that may change as the program runs.
Variable Naming Conventions:
Variabls are commonly named using the underscore _
to separate words or using CamelCase (e.g., thisIsCamelCase
), which starts with a lowercase letter. It's important to follow naming conventions for readability.
Names should reflect the value it represents, enhancing clarity.
Functions: Functions are reusable blocks of code that perform a specific task. For example:
The function print(strName, intNumber)
will print the variables passed into it, with commas adding space between them for readability.
Functions can take inputs and may return outputs, making them essential for achieving more complex operations in programs.
String Methods vs. Functions:
A string method acts on a string to perform specific manipulations or checks. For example, strText = “Name”
is a string, and the operation print(isnumeric(strText))
checks if the string contains only number characters.
In contrast, when you see print(str.Text.isnumeric())
, it means the string method isnumeric()
is directly applied to str.Text
. This method will return False
because the text “Name” does not consist of numeric characters.
Understanding these foundational concepts is crucial as they not only establish the core building blocks of coding but also pave the way for more advanced programming techniques.