Core Building Blocks
In Python, variables are used to store data, and data types define the kind of data a variable can hold. Python is dynamically typed—meaning you don’t need to declare the type explicitly.
Creating Variables
Variables are created the moment you assign a value to them:
# Example
name = "Alice"
age = 25
is_student = TrueCore Data Types in Python
int– Integer numbers (e.g.,42,-7)float– Floating-point numbers (e.g.,3.14,-0.001)str– Strings (text), enclosed in quotes (e.g.,"Hello",'Python')bool– Boolean values:TrueorFalseNoneType– Represents absence of value (None)
Checking Data Types
Use the built-in type() function:
print(type(42)) #
print(type("Hello")) #
print(type(3.14)) # Type Conversion (Casting)
You can convert between types using functions like int(), float(), and str():
x = "10"
y = int(x) # y is now integer 10
z = float(y) # z is now 10.0Important Notes
- Variable names are case-sensitive (
age≠Age). - Must start with a letter or underscore, not a number.
- Cannot use reserved keywords (e.g.,
if,for,class). - Python follows PEP 8 naming conventions: use
snake_casefor variables.