Advanced Python
Advanced Python
Python
Programming
Welcome to the world of Python programming! Python is a
versatile and powerful language that has gained immense
popularity due to its readability, ease of use, and vast
libraries. It's a great language to learn for beginners, and it
can be used for a wide range of applications, from web
development to data science to machine learning.
1 Alphanumeric Characters
Variable names can contain letters (a-z, A-Z), numbers (0-9), and underscores (_).
Strings (str)
Strings are sequences of characters enclosed in single or
double quotes. For example, "Hello, World!" and "Python" are
strings.
Conditional Operators in
Python
" and two numbers displayed, representing the values being compared" />
== Equal to 5 == 5 (True)
The "and" operator returns True The "or" operator returns True if The "not" operator inverts the
if both operands are True, and at least one of the operands is truth value of an operand. If the
False otherwise. & True, and False otherwise. | operand is True, "not" returns
False, and vice versa. !
Integer Conversion
The `int()` function converts a string or other
data type into an integer. This is useful for
performing mathematical operations or
comparing values as integers.
( )
{ }
{ }
Lists in Python
Data Collection
Lists are used to store collections of data, allowing you to organize and access multiple values under a single
variable. NEED TO USE SQUARE BRACKETS.
Indexing
Elements in a list can be accessed using their index, starting from 0 for the first element. For example,
`list[0]` returns the first element. STARTS FROM 0 ->1 (FORWARDING INDEXING) OR -1 -> – N (REVERSE
INDEXING)
Slicing
Slicing allows you to access a range of elements in a list. For example, `list[1:3]` returns a sublist containing
the second and FIRST elements.
Adding Elements
The `append()` function adds elements to the end of a list. The `insert()` function adds elements at a
specific position in the list. EG: list1.append(“RUSSIA”), list1.insert(3, “Russia”)
Lists in Python
Deleting Elements
The `pop()` function removes elements from the end of a list. The `del` function deletes elements at a
specific position in the list. EG: list1.pop(), del list1[2]
Indexing
Elements in a list can be accessed using their index, starting from 0 for the first element. For example,
`list[0]` returns the first element. STARTS FROM 0 ->1 (FORWARDING INDEXING) OR -1 -> – N (REVERSE
INDEXING)
Slicing
Slicing allows you to access a range of elements in a list. For example, `list[1:3]` returns a sublist containing
the second and FIRST elements.
Adding Elements
The `append()` function adds elements to the end of a list. The `insert()` function adds elements at a
specific position in the list. EG: list1.append(“RUSSIA”), list1.insert(3, “Russia”)
Looping and List
Manipulation
1 FOR Loop
The `for` loop iterates through a sequence of values,
executing the code block for each value in the
sequence.
2 WHILE Loop
The `append()` method adds an element to the end of
an existing list, extending its length.