what is python ? python is a high-level, interpreted programing language known for its easy-to-read syntax and powerful capabilities you run the script using the command "python example.py"
indentation - refers to the spaces/tabs to define blocks of code.
variables and data types: python variables dont require explicit declaration and can store diffrent types of data, such as integers,floats, strings
comments : use the # symbol for commments
control flow: learn how to use if,else,elif and loops (For,while) to control the flow of your program
functions : are blocks of reusable code, define
Variables in python: you dont need to explicitly declare a variable or its data type before using it, you simply assign a value to a variable using the = operator
E.G age = 25 name = "Alice"
-naming rules : variables names must start with a letter or an _ -they can contain letters,numbers and underscores but cannot start with a number
- variables are case sensitive (Name and name are diffrent)
DATA TYPES:
integer(int): - represents whole numbers without a decimal point.
E.G age = 30
floating -point number(float): -represents numbers with a decimal point
E.G height = 5.9
string(str): represents sequences of characters enclosed in quotes(single or double)
E.G name = "Alice"
Boolean(bool):
represents one or two values: True or false
is_student = True
Compound data types :
list(list): an ordered collection of items that can contain elements of diffrent data types. lists are mutable,meaning their contents can be changed. e.g fruits["apple","banana","cherry"}
tuple(tuple): similar to lists but tubles are immutable, once created their contents cannot be changed. example: coordinates =(10.0, 20.0)
Dictionary(dict): collection of key-value pairs. each key must be unique ,and values can be of any data type. E.g person ={"name":"alice","age":25}
Set(set): an unordered collection of unique elements. unique_numbers ={1,2,3,4,5}
type conversion: implicit type conversion :
- python automatically converts one data type to another when necesary. for example, adding an integer to a float results in float result = 10 + 3.5 #13.5 (float)
Explicit type conversion: you can manually convert a data type to another using functions like int(),float(),str() and list() example : num_str="100" num_int = int(num_str) # converts string to integer
type checking: use the type() function to check the data type of a variable
example: print(type(age))
Operators and expressions:
- operators and expressions are fundamental concepts in python that allow you to perform various operations on data.
operators- are special symbols or keywords in python that perform operations on variables and values. for example + is an operator used for addition
expressions:
- an expression is a combination of values,variables and operators that python interprets and evaluates to produce a result. for example 2+3 IS A Expression that evalutes to 5