0% found this document useful (0 votes)
5 views15 pages

Python Programming

Python Programing

Uploaded by

pritamgamer1122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views15 pages

Python Programming

Python Programing

Uploaded by

pritamgamer1122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Python

What is Python?
• Python is a high-level, interpreted programming language known for its simplicity and readability.
• It is used in various fields such as web development, data science, artificial intelligence, and more.
• Python emphasizes code clarity, making it ideal for beginners.
Python is also Known as
Object-Oriented Programming
Language
Focuses on objects and classes to organize code,
enabling modularity and reusability (e.g., Java,
Python, C++)
Logic Programming Language
Uses formal logic to express computations, mainly
applied in AI and problem-solving (e.g., Prolog).

Scripting Programming Language


Designed for automating tasks and controlling
software applications (e.g., Python, JavaScript,
Bash).

Functional Programming Language


Emphasizes immutability and pure functions,
avoiding shared state (e.g., Haskell, Lisp).
Procedural Programming Language
Follows a step-by-step approach using functions
and procedures (e.g., C, Pascal).
Why Learn Python?
• Easy to Read & Write: Python's syntax is clear and concise.
• Versatile: Used in a wide range of applications, from web apps to scientific computing.
• Large Community: Extensive libraries, frameworks, and community support help beginners and professionals alike.
• In-Demand Skill: Python programming is highly sought-after in the job market.
Setting Up Your Python Environment?
• Download & Install Python:
• Visit python.org to download the latest version.
• Choose an IDE/Text Editor:
• Options include IDLE, VS Code, PyCharm, or Jupyter Notebook.
• Verify Installation:
• Open your command prompt/terminal and type python --version to confirm installation.
Python Basics & Syntax?
• Python uses indentation instead of curly brackets {} (like in C or Java) to define blocks of
code.
Correct Indentation (4 spaces recommended):
Incorrect Indentation (Error):

if 5 > 3: if 5 > 3:
print("5 is greater than 3") print("5 is greater than 3")

No semicolons
No need for semicolons (;) at the end
of lines

Synta
Enter your text x Case Sensitive
Comments start with # for Case-sensitive (name and Name
single-line and ''' ''' for multi-line comments. Rules are different)
in
Pytho
n
Python Variables
• Variables store values and don’t need a specific type declaration.
Index.py
Variable Naming Rules; {
name = "Alice" # String
age = 25 # Integer
• Must start with a letter or underscore (_) height = 5.7 # Float

• Cannot start with a number (1name ❌). student = True # Boolean

• Can contain letters, numbers, and underscores (_).


• ✔ Case-sensitive: myVar and myvar are different.

}
Python Variables Index.py

• Variables store values and don’t need a specific type declaration. x = "Alice" # String
y = 25 # Integer
Data Type Example Description z = 5.7 # Float
String (str) "Hello" Stores text is_vaild = True # Boolean
Integer (int) Integer (int) Integer (int)

Float (float) 3.14 Decimal numbers

Boolean (bool) True, False Logical values

Tuple (tuple) (1, 2, 3) Ordered, immutable


collection
List (list) [1, 2, 3] Ordered, mutable collection
Ordered, mutable
List (list) [1, 2, 3] collection
Type Conversion (Casting)
• You can convert data types using casting functions.
Index.py

x = 10
print(float(x)) # Converts int to float → 10.0

y = "25“
print(int(y)) # Converts string to int → 25

z = 5.6
print(str(z)) # Converts float to string → "5.6"
Input & Output in Python
• Python allows user input and output printing.

💡 Getting user input: 💡 Printing multiple values:

Index.py Index.py

name = input("Enter your name: ")


print("Python", "is", "awesome!", sep="-")
print("Hello, " + name + "!")
# Output: Python-is-awesome!

Input
Output
Operators in Python
• Variables store values and don’t need a specific type declaration.
Operator Type Example Description
Arithmetic +, -, *, /, //, %, ** Basic math operations
Comparison ==, !=, >, <, >=, <= Compare values
Logical and, or, not Logical operations
Assignment =, +=, -=, *=, /= Assign values

Membership in, not in Check existence in a list

Index.py
y = 10 # Integer
z = 5 # Float
print(a + b) # Addition → 15
print(a > b) # Comparison → True
Conditional Statements (if-else)
• Python uses if, elif, and else for decision-making.

Index.py
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult.")
elif age == 17:
print("Almost there!")
else:
print("You are a minor.")
Loops (for, while) in Python
• Loops help in repeating tasks automatically.

🔹 For loop example 🔹 While loop example:


Index.py
Index.py count = 0
for i in range(5): while count < 5:

print("Iteration:", i) For while


print("Count:", count)
count += 1
Functions in Python
• Functions help organize code and make it reusable.

 Example of a simple function:

Index.py

def greet(name):
print("Hello, " + name + "!")
greet("Alice")

🔹 What are Functions in Python?


• A function is a block of code that performs a specific task.
• Functions help organize and reuse code efficiently.
• Python has built-in functions (like print(), len(), input()) and user- defined functions.

You might also like