0% found this document useful (0 votes)
3 views5 pages

Unit 1 Basic

Python is a high-level, interpreted programming language known for its readability and simplicity, created by Guido van Rossum in 1991. It features a wide range of applications including web development, data science, and machine learning, and offers a variety of built-in data types and operators. Key aspects of Python include its syntax, use of indentation, and input/output functions for user interaction.

Uploaded by

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

Unit 1 Basic

Python is a high-level, interpreted programming language known for its readability and simplicity, created by Guido van Rossum in 1991. It features a wide range of applications including web development, data science, and machine learning, and offers a variety of built-in data types and operators. Key aspects of Python include its syntax, use of indentation, and input/output functions for user interaction.

Uploaded by

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

UNIT–1: Introduction to Python and Basics of

Programming
1. Introduction to Python
Python is a high-level, interpreted, general-purpose programming language
created by Guido van Rossum and first released in 1991. Python
emphasizes code readability and simplicity, making it one of the most
popular programming languages today.

1.1 Features of Python


• Simple and Easy to Learn – Uses English-like syntax and minimal code. •
Interpreted Language – Executes code line by line, making debugging
easier. • High-Level Language – Programmer does not need to manage
memory explicitly. • Object-Oriented – Supports classes, objects,
inheritance, and polymorphism. • Portable – Same code can run on different
platforms (Windows, Linux, macOS). • Extensive Standard Library –
Includes modules for file handling, math, networking, databases, etc. • Open
Source – Free to use and distribute. • Dynamically Typed – No need to
declare variable types explicitly.

1.2 Applications of Python


Python is used in various domains: • Web Development – Django, Flask •
Data Science & Analytics – NumPy, Pandas, Matplotlib • Machine
Learning & AI – TensorFlow, Scikit-learn, PyTorch • Automation &
Scripting – Task automation, testing • Desktop Applications – Tkinter,
PyQt • Game Development – Pygame • Scientific Computing – SciPy •
Cybersecurity – Network scanning, penetration testing

1.3 Installation of Python


Steps to install Python: 1. Visit the official website: [Link] 2.
Download the latest Python version. 3. Run the installer. 4. Check the option
Add Python to PATH. 5. Verify installation using command: python –
version

1.4 Python IDEs


An IDE (Integrated Development Environment) provides tools for
coding, debugging, and testing.
Common Python IDEs: • IDLE – Default Python IDE • PyCharm – Professional
IDE with advanced features • Visual Studio Code – Lightweight and popular
• Jupyter Notebook – Used for data science • Spyder – Scientific
computing

2. Python Syntax
Python syntax is clean and readable. • Code blocks are defined using
indentation instead of braces {}. • Each statement is usually written on a
new line.
Example:
if x > 0:
print("Positive number")

2.1 Indentation
Indentation refers to spaces at the beginning of a line. • Python uses
indentation to define blocks of code. • Commonly 4 spaces are used. •
Incorrect indentation results in IndentationError.
Example:
if x > 0:
print("Hello")
print("Python")

2.2 Comments
Comments are used to explain code and improve readability.
Types of comments: • Single-line comment – Starts with # • Multi-line
comment – Triple quotes (''' or """)
Example:
# This is a single-line comment
'''
This is a multi-line comment
'''

3. Variables
Variables are used to store data values. • No need to declare type explicitly.
• Variable name must start with a letter or underscore. • Cannot start with a
number.
Example:
x = 10
name = "Python"

Rules for Naming Variables


• Must contain only letters, numbers, and underscores • Case-sensitive (age
and Age are different) • Cannot use Python keywords

4. Data Types
Data types specify the type of data stored in a variable.

Built-in Data Types:


• int – Integer values (10, -5) • float – Decimal values (3.14) • complex –
Complex numbers (2+3j) • str – String (“Hello”) • bool – True or False • list
– Ordered, mutable collection • tuple – Ordered, immutable collection • set
– Unordered, unique elements • dict – Key-value pairs
Example:
x = 10 # int
y = 3.5 # float
name = "AI" # string

5. Type Casting
Type casting converts one data type into another.
Types: • Implicit Type Casting – Done automatically by Python • Explicit
Type Casting – Done manually using functions
Common casting functions: • int() • float() • str()
Example:
x = 5
y = float(x)

6. Operators in Python
Operators are used to perform operations on variables and values.
6.1 Arithmetic Operators
• + (Addition) • - (Subtraction) • * (Multiplication) • / (Division) • %
(Modulus) • ** (Exponentiation) • // (Floor Division)

6.2 Relational (Comparison) Operators


• == Equal to • != Not equal to • > Greater than • < Less than • >=
Greater than or equal to • <= Less than or equal to

6.3 Logical Operators


• and – True if both conditions are true • or – True if any condition is true •
not – Reverses the result

6.4 Assignment Operators


• = • += • -= • *= • /= • %=

6.5 Membership Operators


• in – Returns True if value exists in sequence • not in – Returns True if value
does not exist
Example:
'a' in 'apple'

6.6 Identity Operators


• is – True if both variables refer to same object • is not – True if they do not
refer to same object
Example:
x is y

6.7 Bitwise Operators


• & (AND) • | (OR) • ^ (XOR) • ~ (NOT) • << (Left shift) • >> (Right shift)

7. Input and Output


7.1 Input Function
Used to take input from user.
Syntax:
input("Enter value:")
Example:
name = input("Enter your name: ")

7.2 Output Function


Used to display output.
Syntax:
print()

Example:
print("Welcome to Python")

Summary
• Python is a simple, powerful, and versatile programming language. • It
supports multiple data types and operators. • Indentation and syntax are
crucial in Python. • Input and output functions enable user interaction.

End of UNIT–1 Notes

You might also like