0% found this document useful (0 votes)
5 views

Advanced Python

Uploaded by

silvia
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Advanced Python

Uploaded by

silvia
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Introduction to

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.

by Silvia Thomas Padiyath


Python Variable Naming Rules
(similar to insta handle ;))

1 Alphanumeric Characters
Variable names can contain letters (a-z, A-Z), numbers (0-9), and underscores (_).

2 Start with a Letter or Underscore


Variable names must begin with a letter or an underscore. They cannot start
with a number.

3 Avoid Reserved Keywords


Python has reserved keywords like "if," "for," and "while," which are essential
for the language's functionality. These keywords cannot be used as variable
names.

4 Descriptive Naming & Case Sensitive


It's good practice to use descriptive variable names that clearly indicate the
purpose and type of data stored in the variable. Remember Age and aGe are
2different variables in Python.
Python Data Types – to store in variables
Integers (int) Floating-Point Numbers (float)
Integers represent whole numbers without decimal points. Floating-point numbers represent numbers with decimal
For example, 10, 25, and -5 are integers. points. For example, 3.14, -2.5, and 1.0 are floating-point
numbers.

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" />

Operator Meaning Example

== Equal to 5 == 5 (True)

!= Not equal to 5 != 3 (True)

> Greater than 10 > 5 (True)

< Less than 5 < 10 (True)

>= Greater than or 10 >= 10 (True)


equal to

<= Less than or equal to 5 <= 10 (True)


Logical Operators in Python:
Used to compare 2 logical statements

AND Operator OR Operator NOT Operator

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. !

Example activity to try: Positive Even Number - a>0 and a% 2 == 0


Type Conversion in
Python
1 Implicit Type Conversion
Python automatically converts data types in
certain situations, like adding an integer and a
float, resulting in a float for greater accuracy.

2 Explicit Type Conversion


You can explicitly convert data types using
functions like `int()`, `float()`, and `str()`. This
gives you precise control over the type
conversion.
QUESTION: WHAT DO YOU THINK C variable data type will be?

Hint: Computer will pick most accurate choice.


Python Functions:
`int()`, `input()`
Input Function
The `input()` function takes input from the user
and stores it as a string. It prompts the user with
a message, waits for input, and returns the input
as a string.

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.

EXAMPLE TO TRY: INPUT TO CHECK IF NUMBER IS POSITIVE EVEN


[ ]

( )
{ }
{ }
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.

You might also like