Learn practical skills, build real-world projects, and advance your career
Created 3 years ago
Python Revision - Session
Variables
- A variable is a name that refers to a value.
- No declaration required
- Variables must be assigned before being referenced.
- The value stored in a variable can be accessed or updated later.
- No need to specify type to a variable; Python automatically assigns.
- Must begin with a letter (a - z, A - Z) or underscore (_)
- Case Sensitive
- Can be any (reasonable) length
- There are some reserved words which you cannot use as a variable name because Python uses them for other things.
Data Types & Data Structures
-
Built-in data types:
Integer, Floating point, String, Boolean Values -
Additional data structures:
Lists, Dictionary, Sets & Tuples
- Here in the below piece of code you can see that we have assigned each variable with a particular value and use the type method we can check the datatype of the variable
integer_num = 1
floating_num = 1.3
string = 'Mike'
boolean = True
print (type(integer_num))
print (type(floating_num))
print (type(string))
print (type(boolean))
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>