Python 24-Day Course - Day 1: Variables and Data Types

Day 1: Variables and Data Types

Variable Declaration

Python allows you to create variables without declaring a type.

name = "John"
age = 25
height = 175.5
is_student = True

Basic Data Types

TypeExampleDescription
int42Integer
float3.14Floating-point number
str"hello"String
boolTrueBoolean
NoneNoneNo value

Checking Types

x = 42
print(type(x))  # <class 'int'>

y = "hello"
print(type(y))  # <class 'str'>

Type Conversion

# String -> Integer
num = int("123")

# Integer -> String
text = str(456)

# Float -> Integer (decimal part is truncated)
n = int(3.7)  # 3

Today’s Exercises

  1. Store your name, age, and height in variables and print them.
  2. Use the type() function to check the type of each variable.
  3. Convert the string "100" to an integer and add 50 to it.

Was this article helpful?