Basics/principles Flashcards
Variable
A container for a value, it behaves as the value it contains.
Float
A number with a decimal portion
Integer (Int)
A whole number
Type
Can be used to identify the value type of a variable
String or “str”
A series of letters
Boolean
A value that is either “true” or “false”
Multiple assignment
Allows you to give values to multiple variables in one line of code
What is this line of code an example of?
Name, age, cool = “alex”, 15, True
This is an example of multiple assignment
What is this an example of?
Alex = Dino = James = Rhea = “cool”
This is an example of multiple assignment.
Type casting
Converting the data type of a value to another data type e.g from integer to string
Input()
This allows for the user to give input
What is this doing?
Name = input(“What is your name?”)
This is assigning the users input to the variable “Name”
An absolute value
How far away a number is from 0
Slicing
Creating a substring by extracting elements from another string
Indexing[]
A form of slicing that uses square brackets
Slice()
A form of slicing that uses brackets
[start:stop:step]
3 optional arguments needed when slicing
Slicing a string with the square brackets
Alex =“alex”
Print(alex[0:4:1])
Console:
Alex
The start index
Defines where the variable will start.
(Inclusive)
The stop index
Defines where the variable will end.
(Exclusive)
The step index
Defines by how many places the variable is used
E.g
Name = “Alexander”
Print(Name[0:9:2]
Console:
lxne
Difference between slice() and indexing[]
In slicing as an oppose to using colons to separate your indexes [start:stop:step]
You would use commas
(Start,stop,step)
And instead of using square brackets you would use normal brackets)
If statement
A block of code that will only execute if it’s condition is true
Hierarchy in (if , elif, else)
/\
| If
|
| Elif
|
| Else
\/
Logical operators (and,or)
Used to check if two or more conditions are true
The not operator
Changes a true value to false and a false value to true
Assignment operator
=
Equivalent operator
==
The process of linking two different data with types
Concatenation
IDE
Integrated development environment
the difference between return and print()
A Python function without a return statement returns None
What is “I” in a for loop
i or whatever character you choose to assign is a way to extract a value in a variable (“in variable” is referring to any variable)
“for x in variable:
print(x)”
This will print the value of x in the variable.
Nested loops
A loop within a loop
The “inner loop” will finish all of it’s iterations before finishing one iteration of the”outer loop”
Loop control statements
Changes a loops execution from its normal sequence.
Break
Used to terminate the loop entirely
Continue
Skips to the next iteration of the loop
A module
A file containing a set of functions you want to use in your application. e.g “math”
Pass
does nothing, acts as a placeholder
Index operator[]
Gives access to a sequences elements
(Used in strings,lists,tuples but not limited to these three)