0% found this document useful (0 votes)
2 views13 pages

Python Basics for Beginners in BS 7th Semester

The document provides an introduction to Python, highlighting its features such as being a high-level, interpreted language with simple syntax and wide applicability in various fields. It covers the basic structure of Python programming, including comments, variables, data types, and control flow statements, along with example codes. Additionally, it emphasizes the importance of indentation and offers practice exercises to reinforce learning.

Uploaded by

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

Python Basics for Beginners in BS 7th Semester

The document provides an introduction to Python, highlighting its features such as being a high-level, interpreted language with simple syntax and wide applicability in various fields. It covers the basic structure of Python programming, including comments, variables, data types, and control flow statements, along with example codes. Additionally, it emphasizes the importance of indentation and offers practice exercises to reinforce learning.

Uploaded by

ammareverywheree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Python

Basics & Structure for BS 7th


Semester
What is Python?
• • High-level, interpreted programming
language
• • Easy to read and write (simple syntax)
• • Open-source and cross-platform
• • Widely used in web development, data
science, AI, and automation
• • Developed by Guido van Rossum, first
released in 1991
Why Learn Python?
• • Beginner-friendly and versatile
• • Large community and libraries
• • Supports multiple programming paradigms
• • Strong industry demand
• • Excellent for prototyping and production
Python Basic Structure
• • Comments: # This is a comment
• • Variables: x = 10
• • Input/Output: input(), print()
• • Indentation defines code blocks
• • Functions: def my_function():
• • Control statements: if, else, while, for
Python Example Code
• Example:

• name = input("Enter your name: ")


• print("Hello,", name)

• for i in range(5):
• print("Number:", i)
Data Types in Python
• • int → 10
• • float → 10.5
• • str → 'Hello'
• • bool → True/False
• • list → [1, 2, 3]
• • tuple → (1, 2, 3)
• • dict → {'key': 'value'}
• • set → {1, 2, 3}
Summary
• • Python is simple, powerful, and versatile
• • Basic structure includes variables, functions,
control flow
• • Indentation is crucial in Python
• • Supports multiple data types
• • Widely used in many fields (web, AI, data
science)
Practice Code: Variables & I/O
• Example 1:
• x=5
• y = 10
• print("Sum:", x + y)

• Example 2:
• name = input("Enter your name: ")
• print("Welcome,", name)
Practice Code: Control Flow
• Example 1: If-Else
• age = int(input("Enter your age: "))
• if age >= 18:
• print("You are an adult")
• else:
• print("You are underage")

• Example 2: Loop
• for i in range(5):
Flowchart: Python Execution Flow
• Start → Write Python Code → Save as .py →
Run Interpreter → Interpreter Reads Line by
Line → Executes → Output → End
Structure of a Python Program
• General Structure:
• 1. Comments & Documentation
• 2. Import Libraries
• 3. Define Variables & Constants
• 4. Define Functions & Classes
• 5. Main Program (control flow, loops,
conditions)
• 6. Output / Return Results
Practice Code: Functions
• def greet(name):
• return "Hello, " + name

• user = input("Enter your name: ")


• print(greet(user))
Mini Exercise
• Write a Python program that:
• • Takes two numbers as input
• • Prints their sum, difference, product, and
division
• • Checks if the first number is greater than the
second
• • Uses a function for at least one operation

You might also like