Basics/principles Flashcards
(39 cards)
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
\/