Getting started with the basics of python

asharjavidaj 60 views 38 slides Feb 25, 2025
Slide 1
Slide 1 of 38
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38

About This Presentation

Getting started with the basics of python


Slide Content

By Muhammad Ashar GET READY FOR Artificial Intelligence USING PYT HON

What is AI?

Re-Calling Concepts: Print Type casting Input If-Elif-Else (Conditional Statements) Operators Constants, Variables

What is PYT HON ?

PYT HON: General Purpose Programming: Python is versatile and addresses a wide range of programming tasks. Scripting Language: Python automates repetitive tasks like file manipulation and text processing. Interpreted Language: Python's line-by-line execution allows for flexibility and easier debugging. Dual Role: Python develops complex applications and automates simpler tasks efficiently.

History Invented in the Netherlands, in 1991 by Guido van Rossum Named after Monty Python Open sourced from the beginning

Why PYT HON ?

Current Application of PYT HON … Web development                               Software development System scripting Machine Learning Data Science AI, Deep Learning

iNTRODUCTION TO PYT HON Python is a high-level programming language that is widely used in various fields, Some of the key elements of Python include: 01 DATA TYPES 02 VARIABLES 03 OPERATORS 04 CONDITIONAL STATEMENTS 05 LOOPS 06 FUNCTIONS 07 LIBRARIES

Variables: Party Time! Get Your Data On! A variable in Python is just a name that represents a value, and you can use it to store and manipulate data throughout your program. In Python, we’ll try to create a variable called "age" and assign a value to it, like this: Now, whenever you need to use that age value in your program, you can just use the variable name "age". For example: The output will be: 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.

Data Types: So Many Flavors, So Little Time! In Python, data types are categories of values that determine how the values behave and what operations can be performed on them. Here are some common data types and their examples: TYPES DESCRIPTION EXAMPLES Numeric Represents numerical values 'int' , 'float' Sequence Represents a collection of ordered and indexed values 'list' , 'tuple' Text Represents a sequence of characters 'str' Mapping Represents a collection of key-value pairs 'dict' Set Represents a collection of unique elements 'set' Boolean Represents a binary truth value 'bool'

Examples that shows how different data types can be used in Pyt hon :

Operators: Go crazy with Calculations! In Python, operators are symbols or special characters that allow you to perform different kinds of operations on variables and values. TYPES DESCRIPTION EXAMPLES Arithmetic Operators Used to perform arithmetic operations '2 + 3' returns '5' Comparison Operators Used to compare values '2 < 3' returns 'True' Logical Operators Used to combine and manipulate boolean values 'True and False' returns 'False' Bitwise Operators Used to perform bitwise operations 'a & b' returns '1' Assignment Operators Used to assign values to variables 'x=5' Identity Operators Used to compare the memory location of two objects 'x is y' returns 'True' Membership Operators Used to check if a value is present in a sequence '2 in [1, 2, 3]' return 'True'

Input and f string: Ask from user:

Index and Slices: Your Choice:

Conditional Statements: Be the boss of your code! TYPES DESCRIPTION EXAMPLES 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")' If else statement Executes one block of code if a condition is true and another block if it is false See the diagram on Left Side elif statement Executes a block of code if a condition is true, and if not, checks another condition See the diagram on Left Side nested if statement Executes a block of code if a condition is true, and that block can contain another if statement

Loops: Repeat After Me! Loops are used to repeat a block of code multiple times until a certain condition is met. There are two main types of loops in Python: for loops and while loops. INPUT OUTPUT FOR LOOP LOOP TYPE DESCRIPTION 'for' loop Used to iterate over a sequence of elements, such as a list or string 'while' loop Used to repeat a block of code while a certain condition is true WHILE LOOP

FUNCTION TYPE DESCRIPTION Built-in functions Functions that are built in python and can be used without needing to define them. Examples - 'print()' , 'len()' and 'range()' User-defined functions Functions that you create yourself to perform a specific task. They can be reused multiple times throughout your code. Functions: The Superheroes of 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 to rewrite the code. There are two main types of functions in Python: built-in functions and user-defined functions. INPUT OUTPUT Built-in function User- defined function

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: The Most Important Libraries 1. Import Numpy NumPy is a library for numerical computing in Python. It provides fast and efficient array operations and linear algebra routines. 2. Import A rt Art is a library for data manipulation and analysis in Python. It provides different Example for importing NumPy Library in Python Example for importing Art Library in Python

Libraries Continue... ` TextBlob ` is a Python library for processing textual data, offering tools for sentiment analysis, part-of-speech tagging, and translation. The `turtle` library in Python is used for creating simple graphics and drawings by controlling a turtle that moves around the screen. Example for importing TextBlob Library in Python Example for importing Turtle library in Python 3. import TextBlob 4. import turtle

Tasks for Today: Am I an even number? Showcase the use of the following functions: for, while, conditionals Build a calculator using functions (add, subtract, multiply, divide) Use Lists for storing data Use a Dictionary for storing data Exception Handling Slicing
Tags