Master AI & Build your First Coding Portfolio with SkillReactor | Sign Up Now

Lesson 2 - Basic Python Syntax

2.1 Variables And Data Types

Remember the childhood math where we declared x = 10 and then found y = x + 2? Here, x is a variable containing the value 10 that we used to find the value of y.

Similarly, variables in Python are used to store information, which can be numbers, text, lists, etc.

In Python, declaring variables is straightforward. Unlike some other programming languages, you don't need to specify data types like integer, float, or string explicitly.

Declaring a variable with a numeric value:

num = 10
num_float = 10.55
print(num + num_float)  # Outputs: 20.55

Declaring a variable with a character value:

ch = 'a'
print(ch)  # Outputs: a

Declaring a variable with a string value:

txt = "This is a text."
print(txt)  # Outputs: This is a text.

In Python, variables dynamically adapt to the type of data assigned to them, making it flexible and intuitive.