Unit - Viii Python Ch-1 Toch-4
Unit - Viii Python Ch-1 Toch-4
CHAPTER - 1
INTRODUCTION TO PYTHON LANGUAGE
DISADVANTAGES OF PYTHON
Speed
Mobile Development
Memory Consumption
Database Access
Runtime Errors
CHARACTERISTICS OF PYTHON
FEATURES OF PYTHON
Easy-to-learn
Easy-to-read
Easy-to-maintain
Interactive Mode
Portable
Extendable
GUI Programming
Interactive Mode:- Interactive mode is a command line shell which gives immediate feedback for each
statement.
Script Mode:- Script Mode, is used when the user is working with more than one single code or a block
of code. In the script mode, you have to create a file, give it a name with a .py the extension then runs
your code.
CHAPTER – 2
1. Input()
In Python, we have the input() function for taking the user input. The input() function prompts the
user to enter data. It accepts all user input as string. The user may enter a number or a string but
the input() function treats them as strings only.
The syntax for input() is:
name = input("What's your name? ")
print("Nice to meet you " + name )
age = input("Your age? ")
print("My age:”)
2. Print()
Python’s inbuilt function print() is used for printing the information on the screen.
Syntax- print(Message/Value)
COMMENTS
Comments are used in programs for explaining the code. They make the code more readable and
allow different individual to understand the code more effectively and easily.
The comments in python can be either written in a single line or multiple lines. The single line
comments are creating by adding #.
# statements
Single-Line Comments in Python
In Python, we use the hash symbol # to write a single-line comment.
VARIABLE
Variable name is known as identifier. Variable is a name that is used to refer to memory location and used
to hold value. Variable names can be a group of both the letters and digits.
RULES
CHAPTER – 3
In programming, data type is an important concept.Data types are the classification or categorization of
data items.
Data type defines the type of the variable, whether it is an integer variable, string variable, tuple,
dictionary, list etc.
Python has the following data types built-in by default, in these categories:
Python data types are divided in two categories, mutable data types and immutable data types.
Immutable Objects in Python
Immutable Objects are of in-built datatypes like int, float, bool, string, Unicode, and tuple. In simple
words, an immutable object can’t be changed after it is created.
Mutable in Python can be defined as the object that can change or be regarded as something changeable in
nature. Mutable means the ability to modify or edit a value like list, dictionary or set.
In Python, numeric data type represent the data which has numeric value. Numeric value can be
integer, floating number or even complex numbers. These values are defined
as int, float and complex class in Python.
1. Integers – This value is represented by int class. It contains positive or negative whole numbers
(without fraction or decimal). In Python there is no limit to how long an integer value can be.
2. Float –This value is represented by float class. It is a real number with floating point
representation. It is specified by a decimal point. A floating-point number is accurate up to 15 decimal
places.
3. Complex -A number with a real and imaginary component represented as x + 2y.Complex numbers
are written in the form, x + yj, where x is the real part and y is the imaginary part.
A sequence is an ordered collection of similar or different data types. Python has the following built-
in sequence data types:
String
List
Tuple
1. String-A string is a collection of one or more characters put in a single quote or double-quote.
In python there is no character data type, a character is a string of length one. It is represented
by str class.
Example - 1
2. List –List is an ordered sequence of items. It is one of the most used datatype in Python and is
very flexible. All the items in a list do not need to be of the same type. Items separated by commas
are enclosed within brackets [ ].
a = [1, 2.2, 'python']
# list of having only integers
a=[1,2,3,4,5,6]
print(a)
# list of having only strings
b=[“Hello”,”Virat”,” Kohli”]
print(b)
#list of having both integers, floating and strings
c=[“hey”,”you”, 1,2,3,-4,5.5,”go”]
print(c)
3. Tuple –Tuple is an ordered sequence of items same as a list. The only difference is that tuples are
immutable. Tuples once created cannot be modified.
Tuples are used to write-protect data and are usually faster than lists as they cannot change
dynamically.
It is defined within parentheses () where items are separated by commas.
t = (5,'program', 1+3j)
#tuple having only integer type of data.
a=(1,2,3,4)
print(a) #prints the whole tuple
#tuple having multiple type of data.
b=("hello", 1,2,3,"go")
Chapter - 4
Keywords in Python Programming Language
Python Keywords are special reserved words that convey a special meaning to the compiler/interpreter.
Each keyword has a special meaning and a specific operation. Python has a set of keywords that are
reserved words that cannot be used as variable names, function names, or any other identifiers:
The above keywords may get altered in different versions of Python. Some extra might get added or some
might be removed. You can always get the list of keywords in your current version by typing the
following in the prompt.