Basics-of-Python-Programming This repository is aimed at learning the basics of Python Programming Language
Variable Data Types Operators Expression x = 10 # Integer name = "Alice" # String pi = 3.14 # Float is_active = True # Boolean x = 10 # Integer x = "Ten" # Now a String user_age = 25 total_price = 100.50 Use descriptive names to make your code readable user_age = 25 total_price = 100.50 Variable names must start with a letter or an underscore _, but cannot start with a number. Avoid using reserved keywords (e.g., if, for, while) as variable names. Use snake_case for multi-word variable names (e.g., user_name, total_amount). Python allows assigning multiple variables in a single line.
You can also assign the same value to multiple variables:
Use the print() function to display variable values.
name = "Alice" age = 25 print ("Name:" ,name )print ("Age:" ,age )Python variables can store different types of data. These data types include:
Integer(int)
: Whole numbersFloating Point(float)
: Decimal numbersString(str)
: Textual dataBoolean(bool)
: True or False valuesList, Tuple, Dictionary: Collections of datanumbers = [1 ,2 ,3 ]# List coordinates = (4 ,5 )# Tuple user = {"name" :"Alice" ,"age" :25 }# Dictionary a = 10 b = 3 print (a + b )# Output: 13 print (a ** b )# Output: 1000 (10 raised to the power of 3) print (a > b )# Output: True print (a == 10 )# Output: True print (a > 5 and b < 5 )# Output: True print (not (a < 5 ))# Output: True x = 5x += 3print(x) # Output: 8
fruits = ["apple" ,"banana" ,"cherry" ]print ("banana" in fruits )# Output: True print ("grape" not in fruits )# Output: True Example of an expression:
2 + 3 # This expression evaluates to 5 a * b # If a = 4 and b = 5, this evaluates to 20 result = (4 + 5 )* 2 # Evaluates to 18 is_valid = (5 > 2 )and (3 < 4 )# Evaluates to True full_name = "John" + " " + "Doe" # Evaluates to "John Doe" add = lambda x ,y :x + y print (add (3 ,4 ))# Evaluates to 7