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

Python Programming[1]

The document provides an introduction to Python, highlighting its data types, variables, operators, conditional statements, loops, functions, and libraries. It explains key concepts such as numeric, sequence, text, mapping, set, and boolean data types, as well as the use of operators for various operations. Additionally, it covers the importance of libraries like NumPy, Pandas, Matplotlib, and Scikit-learn for data manipulation and analysis.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Python Programming[1]

The document provides an introduction to Python, highlighting its data types, variables, operators, conditional statements, loops, functions, and libraries. It explains key concepts such as numeric, sequence, text, mapping, set, and boolean data types, as well as the use of operators for various operations. Additionally, it covers the importance of libraries like NumPy, Pandas, Matplotlib, and Scikit-learn for data manipulation and analysis.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PYTHON BASICS

ITS POWER & VERSATILITY

Dr Dan
01
DATA TYPES

02
VARIABLES

iNTRODUCTION 03
OPERATORS

TO PYTHON 04
CONDITIONAL
STATEMENTS
Python is a high-level programming
language that is widely used in various
fields, including data 05
LOOPS
science, web development, and artificial
intelligence. Some of the key elements of
06
FUNCTIONS
Python include:

07
LIBRARIES
TYPES DESCRIPTION EXAMPLES

Represents numerical
Numeric 'int' , 'float' , 'complex'
values

Data Types: Sequence


Represents a collection of
ordered and indexed values
'list' , 'tuple' , 'range'

So Many Flavors, So Represents a sequence of


Text
Little Time!
'str'
characters

Represents a collection of
In Python, data types are categories of Mapping
key-value pairs
'dict'
values that determine how the values
behave and what operations can be
Represents a collection of
performed on them. Here are some Set
unique elements
'set' , 'frozenset'

common data types and their examples:


Represents a binary truth
Boolean 'bool'
value

'bytes' , 'bytearray' ,
Binary Represents binary data
'memoryview'
Examples that shows how different data types can be used in
Python:
In Python, we’ll try to create a variable called "age" and
assign a value to it, like this:

Variables: Now, whenever you need to use that age value in your

Party Time! Get program, you can just use the variable name "age". For
example:

Your Data On!


A variable in Python is just a name that
represents a value, and you can use it to The output will be:
store and manipulate data throughout
your program.

Let’s understand the same with a small


example: In this example, the variable "age" is assigned the value 15.
Then, the print statement uses the value of the variable
"age" to output the string "I am 15 years old."

Note: We use the str() function to convert the integer value


of "age" into a string, so we can concatenate it with the
other strings in the output statement.
TYPES DESCRIPTION EXAMPLES

Operators: Arithmetic
Operators
Used to perform arithmetic
operations
'2 + 3' returns '5'

Go crazy with Comparison Used to compare


'2 < 3' returns 'True'
Operators values

Calculations!
Logical Used to combine and 'True and False' returns
In Python, operators are symbols or Operators manipulate boolean values 'False'

special characters that allow you to


perform different kinds of operations on Bitwise Used to perform
'5 & 3' returns '1'
variables and values. Operators bitwise operations

Here's a table that summarizes the Assignment Used to assign values


'x=5'
Operators to variables
different types of operators in Python,
along with their descriptions and
Used to compare the
examples: Identity
memory location of 'x is y' returns 'True'
Operators two objects

Used to check if a
Membership
value is present in a '2 in [1, 2, 3]' return 'True'
Operators sequence
TYPES DESCRIPTION EXAMPLES
Conditional
Statements: If
statement
Executes a block
of code if a condition
is true
'x=5' <br>
'if x>3:'<br>
'print("x is greater than 3")'

Be the boss of your 'x=2' <br>

code!
Executes one block
'if x>3: '<br>
If else of code if a condition
'print("x is greater than 3")' <br>
statement is true and another
'else:' <br>
block if it is false
Conditional statements in allow you to control 'print("x is less than or equal to 3")'

the flow of your program based on certain


'x = 5' <br>
conditions. They are used to make decisions in 'if x > 7: ' <br>
your code, and they help your program to be 'print("x is
Executes a block of
more flexible and responsive to different inputs. elif code if a condition is true,
greater than 7")' <br>
'elif x > 3: '<br>
statement and if not, checks
'print("x is greater than 3 but less
another condition
than or equal to 7")' <br>
Here's a detailed description along with 'else:' <br>
examples that demonstrates the different types 'print("x is less than or equal to 3")'

of conditional statements in Python to perform


various kinds of checks, such as checking if a 'x = 5' <br>
number is greater than a certain value, or if it 'if x > 3:' <br>
Executes a block of
'if x < 7:' <br>
falls within a certain range. When you run this nested if
code if a condition is true,
'print("x is between 3 and7")' <br>
code, you will see the output for each and that block
statement 'else:' <br>
can contain another
conditional statement. if statement
'print("x is greater than or equal to 7")' <br>
'else:'<br>
'print("x is less than or equal to 3")'
Loops: LOOP TYPE DESCRIPTION

Repeat After Me! 'for' loop


Used to iterate over a sequence of elements,
such as a list or string

Loops are used to repeat a block of code multiple


Used to repeat a block of code while a certain
times until a certain condition is met. There are 'while' loop
condition is true
two main types of loops in Python: for loops and
while loops.

Here's an example of a for loop that iterates over


a list of numbers and prints each number along
with the output. In this example, the loop will FOR
continue to run as long as count is greater than 0. LOOP
Each time the loop runs, it prints the value of
count, then subtracts 1 from it. Eventually, count
becomes 0, and the loop stops running.
INPUT OUTPUT
There are also other types of loops in Python,
such as nested loops, which allow you to put one
loop inside another, and break and continue
statements, which allow you to control the flow WHILE
of the loop. LOOP
FUNCTION TYPE DESCRIPTION

Functions: Built-in
functions
Functions that are built in python and can be
used without needing to define them.
Examples - 'print()' , 'len()' and 'range()'
The Superheroes Functions that you create yourself to perform
User-defined
of Code!
a specific task. They can be reused multiple
functions times throughout your code.

Functions are reusable blocks of code that perform


a specific task. They allow you to write a piece of
code once and use it multiple times without having Built-in
to rewrite the code. There are two main types of
functio
functions in Python: built-in functions and user-
defined functions. n
INPUT OUTPUT
In this example, we define a function called
add_numbers() that takes two parameters, a and b.
The function adds a and b together and returns the
sum. We then call the function with the values 2 User-
and 3, which returns 5. Finally, we print the result. defined
functio
n
Functions
Continue...
Here's an example of using the math library to
calculate the square root of a number:

Another example is using the pandas library to


read a CSV file and display its contents:
Python's Top Guns:
Example for importing NumPy
The Most Important Library in Python
Libraries
1. NumPy
NumPy is a library for numerical computing in
Python. It provides fast and efficient array
operations and linear algebra routines.

Example for importing Pandas


2. Pandas Library in Python
Pandas is a library for data manipulation
and analysis in Python. It provides
powerful tools for working with structured
data, such as dataframes and series.
Libraries Example for importing
Matplotlib Library in Python
Continue...
3. Matplotlib
Matplotlib is a library for data visualization
in Python. It provides a variety of plots and
charts for visualizing data, including line
plots, scatter plots, and histograms.
Example for importing Scikit-
4. Scikit-learn learn library in Python
Scikit-learn is a library for machine
learning in Python. It provides tools for
data preprocessing, model selection, and
evaluation, as well as a range of machine
learning algorithms.

You might also like