Python Basics: Variables,
Numbers & Strings
TAKEAWAYS
02
Variables
1 Variables are containers that store data in a
Python program
2 Variables are containers that store data in a
Python program
3 Rules of naming variables correctly,
You can not use reserve words as
variable names (e.g. def, True etc.)
Variable names must start with a letter
or an underscore _
It cannot contain spaces or special
characters (@, #, $, %, etc.)
Underscore _ is a valid character and can
be present at any place in a variable
name
03
Numbers
1 Integer numbers store whole numbers (without
decimal part), e.g. 57
2 Float numbers store fractional numbers with
whole and decimal part, e.g. 57.23
3 type(variable_name) can be used to detect the
data type of a variable
4 / operator is used for division whereas // is used
to retrieve integer part of the division
5 % is a modulo operator, it returns the remainder
of a division operation
04
Numbers
6 x**y will return x raised to the power of y
7 You can do type casting using functions such as
float(), int(), str() etc.
8 float(”10.2”) will convert string value “10.2” to a
float value 10.2
9 math is a handy module in Python that allows
you to run different functions such as sqrt, floor,
ceil etc.
05
Strings
1 In Python, strings are immutable, meaning they
cannot be changed once created.
2 Access specific characters or substrings in
Python using indexing (e.g., name[0]) and
slicing (e.g., name[1 : 5]).
3 Use string formatting techniques like f-strings
(e.g., f'{variable}') for easier and more readable
string composition in Python.
4 Python provides built-in methods for strings,
such as .upper(), .lower(), .split(), and .strip()