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

Unit - Viii Python Ch-1 Toch-4

This document provides an introduction to Python programming, covering its applications, advantages, disadvantages, characteristics, and features. It also discusses fundamental concepts such as inbuilt functions, comments, variables, data types, and keywords in Python. The document highlights the importance of understanding these elements for effective programming in Python.

Uploaded by

Sarthak Gupta
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)
23 views6 pages

Unit - Viii Python Ch-1 Toch-4

This document provides an introduction to Python programming, covering its applications, advantages, disadvantages, characteristics, and features. It also discusses fundamental concepts such as inbuilt functions, comments, variables, data types, and keywords in Python. The document highlights the importance of understanding these elements for effective programming in Python.

Uploaded by

Sarthak Gupta
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

UNIT – VIII

CHAPTER - 1
INTRODUCTION TO PYTHON LANGUAGE

Python is a general-purpose, interpreted, interactive, object-oriented, and high-level programming


language. It was created by Guido van Rossum during 1985- 1990.
APPLICATIONS OF PYTHON
1. Web development
2. Machine learning
3. Data Analysis
4. Scripting
5. Game development
6. Desktop applications
ADVANTAGES OF LEARNING PYTHON
Python is Interpreted
Python is Interactive
Python is Object-Oriented
Python is a Beginner's Language

DISADVANTAGES OF PYTHON

Speed
Mobile Development
Memory Consumption
Database Access
Runtime Errors

CHARACTERISTICS OF PYTHON

 It supports functional and structured programming methods as well as OOP(object oriented


programming).
 It can be used as a scripting language or can be compiled to byte-code for building large
applications.
 It provides very high-level dynamic data types and supports dynamic type checking.
 It supports automatic garbage collection.
 It can be easily integrated with C, C++ and Java.

FEATURES OF PYTHON

 Easy-to-learn
 Easy-to-read
 Easy-to-maintain
 Interactive Mode
 Portable
 Extendable
 GUI Programming

MODES OF WORKING IN PYTHON IDLE


We can work in two ways:

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

FUNDAMENTALS OF PYTHON PROGRAMMING

INBUILT FUNCTION OF PYTHON

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 #.

The syntax for writing single-line comments in Python is:-

# statements
Single-Line Comments in Python
In Python, we use the hash symbol # to write a single-line comment.

Example1: Writing Single-Line Comment


print('Hello world') #printing a string
Here, the comment is: #printing a string
Multi-Line Comments in Python
Python does not provide the option for multiline comments. However, there are different ways through
which we can write multiline comments.
a. Multiline comments using multiple hashtags (#)

# Python program to demonstrate


# multiline comments
print("Multiline comments")

b. triple quotes(“””) as multiline comments.


""" Python program to demonstrate
multiline comments"""
print("Multiline comments")

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

The rules to name an identifier are given below:

 The first character of the variable must be an alphabet or underscore (_).


 All the characters except the first character may be an alphabet of lower-case (a-z),
upper-case(A-Z), underscore, or digit (0-9).
 Identifier name must not contain any white-space, or special character (!,@,
#,%, ^,&, *).
 Identifier name must not be similar to any keyword defined in the language.
 Identifier namesarecasesensitive;forexample,myname,andMyNameis notthesame.
 Examples of valid identifiers: a123,_n,n_9,etc.
 Examples of invalid identifiers: 1a, n%4,n9, etc.

CHAPTER – 3

DATA TYPES TO PYTHON PROGRAMMING LANGUAGE

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:

Numeric Types: int, float, complex

Sequence Types: list, tuple, str

Mapping Type: dict

Set Types: set, frozenset

Boolean Type: bool

Binary Types: bytes, bytearray, memoryview

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 Objects in Python

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.

Python Numeric Data Type

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.

e.g. -10, 10, 456, 4654654.

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.

e.g. – 25.78,10.45, 12.567883

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.

Python Sequence Data Type

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

str = "string using double quotes"


print(str)

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.

>>> import keyword


>>> print(keyword.kwlist)

You can also get a list of available keywords by using help():


>>>
>>> help("keywords")

In Python, keywords are case sensitive.


There are 33 keywords in Python 3.7 and Python 2 has 30.
There are 36 keywords in Python 3.9.
All the keywords except True, False and None are in lowercase and they must be written as they are.

You might also like