Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

Python Notes - 1

Python is an interpreted, object-oriented programming language that can be used for web development, business applications, GUI applications, games, artificial intelligence, and more. It was created by Guido van Rossum in the late 1980s and continues to gain popularity due to its simplicity, versatility, and vast library of modules. Python code can run on Windows, Linux, Mac OS, and other operating systems.

Uploaded by

Prasad S R
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Python Notes - 1

Python is an interpreted, object-oriented programming language that can be used for web development, business applications, GUI applications, games, artificial intelligence, and more. It was created by Guido van Rossum in the late 1980s and continues to gain popularity due to its simplicity, versatility, and vast library of modules. Python code can run on Windows, Linux, Mac OS, and other operating systems.

Uploaded by

Prasad S R
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

 Python is a programming language

 It is a interpreted ,object oriented ,high level language


 It supports procedure oriented programming as well as object oriented programming
 It is a simple language( any one can learn)
 It is open source (free download)
 It is portable, Executes in any operating system (windows, Linex , mac)
 It has memory management (allocation and De-allocation of variable memory)
 It has Standard Library with functions- (no need to write code simply use functions)
 Python 1989
 Python is easiest learning programming language
 Python is using in Google, dropbox, YouTube, Yahoo as main language or supporting language
 Python author Guido Van Rossum, he is a fan of movie "Monty python flying circus"
 Everyone can write python code with little bit programming knowledge
 Python versions
Guido van Rossum began working on Python in the late 1980s, as a successor to the ABC
programming language, and first released it in 1991 as Python 0.9.0, and Python 2.0 was
released in 2000
Python 2.0 October 2000-2020

Python 3.0 December 2008

Latest Python 3.9.5


 Web and Internet Development
 Business Applications
 GUI applications
 Games
 Arificial intaligence software
 Network Programming
 Database Access
Difference
: compiler will start process after all completion of source code
: Interpreter LINE by LINE from the source, error detection is problem
1 Python Software
2 Integrated Development Environments (IDE)

o We can download Python Software from website http://www.python.org


o Python with a different OS? Python for Windows, Linux/UNIX, Mac OS
o
o
Variables
Python Keywords
Keywords are the reserved words in Python.
We cannot use a keyword as a variable name, function name or any other identifier. They are
used to define the syntax and structure of the Python language.
In Python, keywords are case sensitive.
There are 33 keywords in Python 3.7. This number can vary slightly over the course of time.
All the keywords except True, False and None are in lowercase and they must be written as
they are. The list of all the keywords is given below.
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
List
Numbers
num=[20,30,40,50]
Strings
names=['ravi','raju','vamsi','manoj']
Both numbers and strings
names=[10,20.234, 'ravi']
Operations
append
listname.append(val)
insert
listname.insert(pos,val)
remove
listname.remove(val)
pop
listname.pop(pos)
listname.pop()
extend
listname.extend ([val1,val2…])
min
min(listname)
max
max(listname)
sum
sum(listname)
sort
listname.sort()
count
vowels = ['a', 'e', 'i', 'o', 'i', 'u']
vowels.count('i')
index
list.index(element, start, end)
reverse
list.reverse()
clear
list.clear()
Tuple
A tuple is created by placing all the items (elements) inside parentheses (), separated by commas. The
parentheses are optional, however, it is a good practice to use them.
A tuple can have any number of items and they may be of different types (integer, float, list, string, etc.).

# Different types of tuples


# Empty tuple # tuple unpacking is also possible
my_tuple = () a, b, c = my_tuple
print(my_tuple) print(a) # 3
print(b) # 4.6
# Tuple having integers print(c) # dog
my_tuple = (1, 2, 3)
print(my_tuple) # Accessing tuple elements using indexing
my_tuple = ('p','e','r','m','i','t')
# tuple with mixed datatypes print(my_tuple[0]) # 'p'
my_tuple = (1, "Hello", 3.4) print(my_tuple[5]) # 't'
print(my_tuple)
# IndexError: list index out of range
# nested tuple # print(my_tuple[6])
my_tuple = ("mouse", [8, 4, 6], (1, 2, 3)) # Index must be an integer
print(my_tuple) # TypeError: list indices must be integers, not
float
#tuple unpacking # my_tuple[2.0]
my_tuple = 3, 4.6, "dog" # nested tuple
print(my_tuple) n_tuple = ("mouse", [8, 4, 6], (1, 2, 3))
# nested index print(my_tuple[:-7])
print(n_tuple[0][3]) # 's' # elements 8th to end
print(n_tuple[1][1]) #4 # Output: ('i', 'z')
print(my_tuple[7:])
# Negative indexing for accessing tuple elements # elements beginning to end
my_tuple = ('p', 'e', 'r', 'm', 'i', 't') # Output: ('p', 'r', 'o', 'g', 'r', 'a', 'm', 'i', 'z')
# Output: 't' print(my_tuple[:])
print(my_tuple[-1])
# Output: 'p' # Deleting tuples
print(my_tuple[-6]) my_tuple = ('p', 'r', 'o', 'g', 'r', 'a', 'm', 'i', 'z')
# can't delete items
# Accessing tuple elements using slicing # TypeError: 'tuple' object doesn't support item
my_tuple = ('p','r','o','g','r','a','m','i','z') deletion
# elements 2nd to 4th # del my_tuple[3]
# Output: ('r', 'o', 'g') # Can delete an entire tuple
print(my_tuple[1:4]) del my_tuple
# elements beginning to 2nd # NameError: name 'my_tuple' is not defined
# Output: ('p', 'r') print(my_tuple)

my_tuple = ('a', 'p', 'p', 'l', 'e',) # In operation


print(my_tuple.count('p')) # Output: 2 print('a' in my_tuple)
print(my_tuple.index('l')) # Output: 3 print('b' in my_tuple)
# Not in operation
# Membership test in tuple print('g' not in my_tuple)
my_tuple = ('a', 'p', 'p', 'l', 'e',)
Program 1
# This program adds two numbers
num1 = 1.5
num2 = 6.3
# Add two numbers
sum = num1 + num2
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

Program 2
# Store input numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
# Add two numbers
sum = float(num1) + float(num2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

You might also like