Professional Documents
Culture Documents
Unit 1
Unit 1
Presentation
On
“Programming with Python”
By
Ms. H. C Kunwar
Lecturer
Unit 1
(08 Marks)
Lecture-1
It is used for:
• web development (server-side),
• software development, mathematics, system scripting.
RAISONI GROUP OF INSTITUTIONS 3
Why Python?
Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
Python has syntax that allows developers to write programs with fewer lines
functional way.
3. Object-Oriented Language:
One of the key features of python is Object-Oriented programming. Python supports
object-oriented language and concepts of classes, objects encapsulation, etc.
4. GUI Programming Support:
Graphical User interfaces can be made using a module such as PyQt5, PyQt4, wxPython, or Tk
in python.
5. Interpreted Language:
Python is an Interpreted Language because Python code is executed line by line at a time. like
other languages C, C++, Java, etc. there is no need to compile python code this makes it easier
to debug our code. The source code of python is converted into an immediate form
called bytecode.
RAISONI GROUP OF INSTITUTIONS 5
Features of Python Programming
8. Extensible feature:
Python is a Extensible language. We can write us some Python code into C or C++
language and also we can compile that code in C/C++ language.
Identifiers :
A Python identifier is a name used to identify a variable, function, class,
module or other object. An identifier starts with a letter A to Z or a to z or
an underscore (_) followed by zero or more letters, underscores and digits
(0 to 9). ... All other identifiers start with a lowercase letter.
User-defined identifiers can consist of letters, digits, underscores, and the
dollar-sign $
Must start with a non-digit
Identifiers are case sensitive (count and Count are different variables)
Reserved words (keywords) cannot be used as identifiers
An identifier can be any length
Keywords :
• Keywords are reserved words in Python and used to perform an internal
operation.
• All the keywords of Python contain lower-case letters only.
• Example:
In the above code, the first and last line of the statement is related to the same suite because
there is no indentation in front of them.
Note : By default, Python uses four spaces for indentation, and the programmer can
manage it. RAISONI GROUP OF INSTITUTIONS 10
1.2 Python Building Blocks?
Variables :
A name that represents a value stored in the computer memory. Used to access
and manipulate data stored in memory.
Python GUI:
There are various GUI based Python IDE that python programmers can use for
better coding experience.
An IDE (Integrated Development Environment) understand your code much better than a
text editor. It usually provides features such as build automation, code linting, testing and
debugging. This can significantly speed up your work. The downside is that IDEs can be
complicated to use.
• PyCharm
• Python IDLE
• The Python Bundle
• pyGUI
• Sublime Text etc.
Python Script:
Output:
# Python program to
# demonstrate numeric value
a=5
print("Type of a: ", type(a)) Output:
Type of a: <class 'int'>
b = 5.0
print("\nType of b: ", type(b)) Type of b: <class 'float'>
String :
In Python, Strings are arrays of bytes representing Unicode characters.
A string is a collection of one or more characters put in a single quote,
double-quote or triple quote.
In python there is no character data type, a character is a string of length
one.
It is represented by str class.
Example:
# Creating a String with double Quotes String with the use of Double
String1 = "I'm a ABC" Quotes:
print("\nString with the use of Double Quotes: ")
I'm a ABC
print(String1)
print(type(String1)) <class 'str'>
# Creating a String with triple Quotes String with the use of Triple Quotes:
String1 = '''I'm a Geek and I live in a world of "Geeks"''' I'm a Geek and I live in a world of
print("\nString with the use of Triple Quotes: ") "Geeks"
print(String1) <class 'str'>
print(type(String1))
# Creating String with triple Quotes allows multiple
Creating a multiline String:
lines
String1 = '''Geeks Geeks
For For
Life''' Life
print("\nCreating a multiline String: ")
print(String1)
RAISONI GROUP OF INSTITUTIONS 20
1.5 Tuple Data Types?
Tuple:
Tuples are used to store multiple items in a single variable.
Tuple is one of 4 built-in data types in Python used to store collections of data,
the other 3 are List, Set, and Dictionary, all with different qualities and usage.
A tuple is a collection which is ordered and unchangeable.
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.).
List :
Lists are one of 4 built-in data types in Python used to store collections of data,
the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.
List items are indexed, the first item has index [0], the second item has index [1]
etc.
Dictionary :
Dictionary in Python is an unordered collection of data values, used to store
data values like a map, which unlike other Data Types that hold only single
value as an element, Dictionary holds key:value pair.
Key value is provided in the dictionary to make it more optimized.
Dictionary can be created by placing sequence of elements within curly {}
braces, separated by ‘comma’.
Values in a dictionary can be of any datatype and can be duplicated, whereas
keys can’t be repeated and must be immutable.
Dictionary keys are case sensitive, same name but different cases of Key will
be treated distinctly.
Output
Dictionary with the use of Integer Keys:
{1: 'Geeks', 2: 'For', 3: 'Geeks'}