0% found this document useful (0 votes)
4 views26 pages

python book

The document provides an introduction to Python, highlighting its creation by Guido Van Rossum in the early 1990s and its advantages such as simple syntax and powerful features. It covers essential programming concepts including identifiers, keywords, comments, and literals, along with examples of print functions and code snippets in Python. Additionally, it explains the importance of comments in programming and provides guidelines for writing identifiers and using keywords.

Uploaded by

kumargourabh101
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)
4 views26 pages

python book

The document provides an introduction to Python, highlighting its creation by Guido Van Rossum in the early 1990s and its advantages such as simple syntax and powerful features. It covers essential programming concepts including identifiers, keywords, comments, and literals, along with examples of print functions and code snippets in Python. Additionally, it explains the importance of comments in programming and provides guidelines for writing identifiers and using keywords.

Uploaded by

kumargourabh101
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/ 26

Introduction to Python

CSE1001: Dr. P. Padmanathan 1


Introduction to Python
• Guido Von Rossum (in early 1990s) created python

CSE1001: Dr. P. Padmanathan 2


The advantages of python are,
• It has simple syntax
• Programs are clear and easy to read
• Provides powerful programming features
• Widely used (YouTube, Google, Yahoo, etc.. )
• It is an open source language

CSE1001: Dr. P. Padmanathan 3


IDE or IDLE
• Integrated Development Environment
• Is a bundle of software tool for program development
• It includes Editor, translator and a debugger

CSE1001: Dr. P. Padmanathan 4


C
#include <stdio.h>
// main function - where the execution of program begins
int main()
{

// prints the string


printf(“I am a Programmer");

return 0;
}
CSE1001: Dr. P. Padmanathan 5
C++
// Header file for input output functions
#include <iostream>
using namespace std;
// main function - where the execution of program begins
int main()
{
// prints the given string
cout << “I am a programmer";

return 0;
}
CSE1001: Dr. P. Padmanathan 6
Python
print(“I am a Programmer”)

CSE1001: Dr. P. Padmanathan 7


Print function in Python
Examples
>>>print("Python")
Python
>>>print("Python", "Programming")
Python Programming
>>> print("Python", "Programming",sep="-")
Python-Programming
>>> print(" Python"," Programming ",sep="YY")
PythonYYProgramming

CSE1001: Dr. P. Padmanathan 8


Print function in Python
Examples
>>> print(“Python",“Programming",sep=",",end="a")
print("""This is a
multiple line print statement""")
print(""" "This is a print statement" """)

CSE1001: Dr. P. Padmanathan 9


What is an Identifier?
• An identifier is a sequence of one or more characters used
to name a given program element.
• Python Identifiers are user-defined names to represent a
variable, function, class, module or any other object. If you
assign some name to a programmable entity in Python, then
it is nothing but technically called an identifier.
• In Python, an identifier may contain letters and digits, but
cannot begin with a digit.
• Special underscore character can also be used
Examples : line, salary, emp1, emp_salary
CSE1001: Dr. P. Padmanathan 10
Rules for Identifier
Python is case sensitive, thus, Line is different from line.
Identifiers may contain letters and digits, but cannot begin with
a digit.
The underscore character ( _ ) is also allowed to aid in the
readability of long identifier names. It should not be used as the
first character
Spaces are not allowed as part of an identifier.

CSE1001: Dr. P. Padmanathan 11


Examples

CSE1001: Dr. P. Padmanathan 12


Identifier examples
>>> first_number=10
>>> second_number=11
>>> result = first_number+second_number
>>> print(result)
21

CSE1001: Dr. P. Padmanathan 13


Keywords in Python
• Keywords are the reserved words in Python.
• It is an identifier that has pre-defined meaning in a
programming language.
• We cannot use a keyword as 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.3. This number can vary
slightly in course of time.
• All the keywords except True, False and None are in lowercase
and they must be written as it is.
CSE1001: Dr. P. Padmanathan 14
Python Keywords
• The list of all the keywords are given below.
False class finally is return
None continue for lambda try
True def from nonlocal while
and del global not with
as elif if or yield
assert else import pass
break except in
CSE1001: Dr. P. Padmanathan raise 15
Checking Keywords
>>> import keyword
>>> keyword.iskeyword("break")
True
>>> keyword.iskeyword(“Python")
False

CSE1001: Dr. P. Padmanathan 16


Comments (#)
Meant as documentation for anyone reading the code
Single-line comments begin with the hash character ("#") and
are terminated by the end of line.
Python ignores all text that comes after # to end of line
Comments spanning more than one line are achieved by
inserting a multi-line string (with """ as the delimiter one each
end) that is not used in assignment or otherwise evaluated, but
sits in between other statements.
""" This is an example of a multiline comment that spans
multiple lines ... ”””
CSE1001: Dr. P. Padmanathan 17
Comments in Python
• Writing comments is a good programming practice.
They are non-executable part of the code, yet quite
essential in a program.
• These not only help other programmers working on the
same project but the testers can also refer them for
clarity on white-box testing.

CSE1001: Dr. P. Padmanathan 18


Examples
#this is just a comment line and will not
be executed
#for every comment line start it with a #

Multiline Comment:
print(""" "This is
a print statement" """)

CSE1001: Dr. P. Padmanathan 19


Literals
• A literal is a sequence of one or more characters
that stands for itself.
• Numerical literals
• String literals

CSE1001: Dr. P. Padmanathan 20


Numeric literal
• A numeric literal is a literal containing only the digits 0–9, an
optional sign character (1 or 2),
and a possible decimal point. (The letter e is also used in
exponential notation).

• If a numeric literal contains a decimal point, then it denotes a


floating-point value, or “float” (e.g., 10.24); otherwise, it
denotes an integer value (e.g., 10).

• Commas are never used in numeric literals.


CSE1001: Dr. P. Padmanathan 21
Numeric Literals in Python

Since numeric literals without a provided sign character denote positive values, an explicit positive sign character
is rarely used.

CSE1001: Dr. P. Padmanathan 22


CSE1001: Dr. P. Padmanathan 23
String Literals
• String literals, or “strings,” represent a sequence of
characters,
'Hello‘, ' padmanathan' "VIT, Vellore 632014"
• In Python, string literals may be surrounded by a
matching pair of either single (') or
double (") quotes.
>>> print('Welcome to Python!')
>>>Welcome to Python!
CSE1001: Dr. P. Padmanathan 24
String Literal Values

CSE1001: Dr. P. Padmanathan 25


CSE1001: Dr. P. Padmanathan 26

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy