0% found this document useful (0 votes)
6 views6 pages

Unit I - PYTHON

Python is a high-level, interpreted programming language known for its readability and versatility, developed by Guido van Rossum in 1991. It is widely used in various domains such as web development, data science, machine learning, and automation, supported by extensive libraries and frameworks. Python's features include easy learning, cross-platform compatibility, dynamic typing, and being open source.

Uploaded by

senpaibot8267
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)
6 views6 pages

Unit I - PYTHON

Python is a high-level, interpreted programming language known for its readability and versatility, developed by Guido van Rossum in 1991. It is widely used in various domains such as web development, data science, machine learning, and automation, supported by extensive libraries and frameworks. Python's features include easy learning, cross-platform compatibility, dynamic typing, and being open source.

Uploaded by

senpaibot8267
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
You are on page 1/ 6

PYTHON is a popular high-level, interpreted programming language.

It was developed by Guido


van Rossum in 1991 and later by the Python Software Foundation. It was designed with a focus on
readability of code, and its syntax enables programmers to convey their ideas in less code. Python is
a programming language that allows you to work fast and integrate systems more effectively.

Used for:
1) Web Development: Frameworks like Django, Flask.
2) Data Science and Analysis: Libraries like Pandas, NumPy, Matplotlib.
3) Machine Learning and AI: TensorFlow, PyTorch, Scikit-learn.
4) Automation and Scripting: Automate repetitive tasks.
5) Game Development: Libraries like Pygame.
6) Web Scraping: Tools like BeautifulSoup, Scrapy.
7) Desktop Applications: GUI frameworks like Tkinter, PyQt.
8) Scientific Computing: SciPy, SymPy.
9) Internet of Things (IoT): MicroPython, Raspberry Pi.
10) DevOps and Cloud: Automation scripts and APIs.
11) Cybersecurity: Penetration testing and ethical hacking tools.

Why PYTHON
1) Easy to Learn and Use: Python’s simple and readable syntax makes it beginner-friendly.
2) Cross-Platform Compatibility: Python runs seamlessly on Windows, macOS, and Linux.
3) Extensive Libraries: Includes robust libraries for tasks like web development, data
analysis, and machine learning.
4) Dynamic Typing: Variable types are determined automatically at runtime, simplifying code
writing.
5) Versatile: Supports multiple programming paradigms, including object-oriented, functional,
and procedural programming.
6) Open Source: Python is free to use, distribute, and modify.

SIMPLE PROGRAMS:
print("Hey there!")
------------------------------------------------------------------------------------------------------------------------
print(5 * 10)
------------------------------------------------------------------------------------------------------------------------
name = input("What's your name? ")
print("Nice to meet you, " + name)
------------------------------------------------------------------------------------------------------------------------
# taking two inputs at a time
x, y = input("Enter two values: ").split()
print("Number of Males: ", x)
print("Number of Females: ", y)
------------------------------------------------------------------------------------------------------------------------
# taking three inputs at a time
x, y, z = input("Enter Total number of students, Male Students & Female Students: ").split()
print("Total number of students: ", x)
print("Number of Male students: ", y)
print("Number of Female students: ", z)
------------------------------------------------------------------------------------------------------------------------
# Prompting the user for input

1 YASH TRIPATHI
age_input = input("Enter your age: ")
------------------------------------------------------------------------------------------------------------------------
# Converting the input to an integer
age = int(age_input)

# Checking conditions based on user input


if age < 0:
print("Please enter a valid age.")
elif age < 18:
print("You are a minor.")
elif age >= 18 and age < 65:
print("You are an adult.")
else:
print("You are a senior citizen.")
------------------------------------------------------------------------------------------------------------------------
for i in range(5):
print("Python is awesome")
------------------------------------------------------------------------------------------------------------------------
name = 'Ayush'
age = 20
print(f"Hello, My name is {name} and I'm {age} years old.")
------------------------------------------------------------------------------------------------------------------------
import random

secret = random.randint(1, 10)


guess = int(input("Guess a number between 1 and 10: "))

if guess == secret:
print("Correct! You win!")
else:
print("Nope, it was", secret)
Note: Python doesn’t automatically load every tool — because that would be super slow. So you
only load what you need, and in this case, random gives you all kinds of cool, unpredictable
behavior.
------------------------------------------------------------------------------------------------------------------------
import random
num = random.randint(1, 10)
print(num)
------------------------------------------------------------------------------------------------------------------------
import random
colors = ["red", "blue", "green", "yellow"]
pick = random.choice(colors)
print("The chosen color is:", pick)
------------------------------------------------------------------------------------------------------------------------
import random
def roll_dice():
return random.randint(1, 6)
print("You rolled:", roll_dice())
------------------------------------------------------------------------------------------------------------------------

2 YASH TRIPATHI
import random
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
print("You rolled:", die1, "and", die2)
print("Total:", die1 + die2)
------------------------------------------------------------------------------------------------------------------------
We can use ‘%’ operator. % values are replaced with zero or more value of elements. The
formatting using % is similar to that of ‘printf’ in the C programming language.

%d –integer
%f – float
%s – string
%x –hexadecimal
%o – octal
------------------------------------------------------------------------------------------------------------------------
# Taking input from the user
num = int(input("Enter a value: "))
add = num + 5
# Output
print("The sum is %d" %add)
------------------------------------------------------------------------------------------------------------------------

input() raw_input()
raw_input() function takes the input from the
1 input() function take the user input. user.
Its syntax is -: Its syntax is -:
2 input(prompt) raw_input(input)
3 It takes only one parameter that is prompt. It takes only one parameter that is the input.
4 It return the input that it takes. Its return type is of string.
It converts the input into a string by removing the
5 trailing newline It is only introduced in python 2.0 version
6 blocks until input received hang ’till user inputs
7 “hello world” “hello world” but string
8 foo in snake_case

3 YASH TRIPATHI
OPERATORS in general are applied to operate upon values and variables. They are typical
symbols employed for logical and arithmetic operations. In this article, we shall examine various
types of operators in Python.

1) OPERATORS: These are the special symbols. Eg- +, *, /, etc.


2) OPERAND: It is the operand on which the operator is performed.

Types of Operators in Python


1) Arithmetic Operators
2) Comparison Operators
3) Logical Operators
4) Bitwise Operators
5) Assignment Operators
6) Identity Operators and Membership Operators
------------------------------------------------------------------------------------------------------------------------
Variables
a = 15
b=4
# Addition
print("Addition:", a + b)
# Subtraction
print("Subtraction:", a - b)
# Multiplication
print("Multiplication:", a * b)
# Division
print("Division:", a / b)
# Floor Division
print("Floor Division:", a // b)
# Modulus
print("Modulus:", a % b)
# Exponentiation
print("Exponentiation:", a ** b)
------------------------------------------------------------------------------------------------------------------------
Comparison of Python Operators
In Python Comparison of Relational operators compares the values. It either returns True or False
according to the condition.

4 YASH TRIPATHI
a = 13
b = 33
print(a > b) False
print(a < b) true
print(a == b) false
print(a != b) true
print(a >= b) false
print(a <= b) true
------------------------------------------------------------------------------------------------------------------------
Logical Operators in Python
Python Logical operators perform Logical AND, Logical OR and Logical NOT operations. It is
used to combine conditional statements.
The precedence of Logical Operators in Python is as follows:

Logical not
logical and
logical or.

a = True
b = False
print(a and b) false
print(a or b) true
print(not a false
------------------------------------------------------------------------------------------------------------------------
Bitwise Operators in Python
Python Bitwise operators act on bits and perform bit-by-bit operations. These are used to operate on
binary numbers.
Bitwise Operators in Python are as follows:
Bitwise NOT
Bitwise Shift
Bitwise AND
Bitwise XOR
Bitwise OR
a = 10
b=4

print(a & b) 0
print(a | b) 14
print(~a) -11
print(a ^ b) 14
print(a >> 2) 2
print(a << 2) 40
------------------------------------------------------------------------------------------------------------------------
Assignment Operators in Python
Python Assignment operators are used to assign values to the variables. This operator is used to
assign the value of the right side of the expression to the left side operand.
Example of Assignment Operators in Python:
a = 10

5 YASH TRIPATHI
b=a
print(b) 10
b += a
print(b) 20
b -= a
print(b) 10
b *= a
print(b) 100
b <<= a
print(b) 102400
------------------------------------------------------------------------------------------------------------------------
Identity Operators in Python
In Python, is and is not are the identity operators both are used to check if two values are located on
the same part of the memory. Two variables that are equal do not imply that they are identical.
is True if the operands are identical
is not True if the operands are not identical
Example of Identity Operators in Python:
------------------------------------------------------------------------------------------------------------------------
a = 10
b = 20
c=a
print(a is not b) True
print(a is c) true
------------------------------------------------------------------------------------------------------------------------
PYTHON DATA types are the categorization or classification of data items. It is the type of value
which indicates what operations can be done on a given data. As everything is an object in Python
programming, Python data types are classes and variables are objects (instances) of these classes.
The following are the built-in or standard data types in Python:

Numeric – int, float, complex


Sequence Type – string, list, tuple
Mapping Type – dict
Boolean – bool
Set Type – set, frozenset
Binary Types – bytes, bytearray, memoryview
------------------------------------------------------------------------------------------------------------------------

ASSIGNMENT

Write a short note on following data types:

1) Numeric: a. Integer b. Float c. Complex


2) Sequence: a. String b. List c. Tuple
3) Dictionary
4) Boolean
5) Set
6) Binary

6 YASH TRIPATHI

You might also like