Python freecodeacmp Flashcards
A variable is
a name that references or points to an object. You can declare a variable by using the assignment operator = to assign a value like this:
variable_name = value
Variables can store
values of different data types.
Strings are
sequences of characters enclosed by single or double quotes, but you cannot start a string with a single quote and end it with a double quote or vice versa
print()
built-in function to print the output of your code on the terminal
Each string character can be referenced by
a numerical index. The index count starts at zero. So the first character of a string has an index of 0.
The last character has an index of
-1
the second to last has index of
-2
You can access the number of characters in a string with
the built-in len() function.
type() is
built-in function which returns the data type of a variable.
Key aspects of variable naming in Python are:
1-Some words are reserved keywords (e.g. for, while, True). They have a special meaning in Python, so you cannot use them for variable names.
2-Variable names cannot start with a number, and they can only contain alpha-numeric characters or underscores.
3-Variable names are case sensitive, i.e. my_var is different to my_Var and MY_VAR.
4-Finally, it is a common convention to write variable names using snake_case, where each space is replaced by an underscore character and the words are written in lowercase letters.
find() function:
built-in function used to locate the character, find() returns the index of the matching character inside the string. If the character is not found, it returns -1
lower() function.
transform a string into its lowercase
for i in
how to write it
indentation
Python relies on indentation to indicate blocks of code. A colon at the end of a line is a signal that a new indented block of code will follow.
An argument is
an object or an expression passed to a function — between the parentheses — when it is called. The print function can take multiple arguments, separated by a comma.