0% found this document useful (0 votes)
15 views

Python UNIT 1

The document outlines the basics of Python programming, including data types like integers, floats, strings, lists, tuples, sets, and dictionaries; variables and how they are declared and initialized; and common Python concepts such as operators, expressions, indentation, comments, and casting. It also discusses Python editors and interpreters as well as how to interact with Python programs.

Uploaded by

Anubhav Maurya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Python UNIT 1

The document outlines the basics of Python programming, including data types like integers, floats, strings, lists, tuples, sets, and dictionaries; variables and how they are declared and initialized; and common Python concepts such as operators, expressions, indentation, comments, and casting. It also discusses Python editors and interpreters as well as how to interact with Python programs.

Uploaded by

Anubhav Maurya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

BBS GROUP OF INSTITUTIONS

Contents
Programming Basics and Decision Making
1. Introduction:
Key features and applications of Python,
Python Editors and Compilers (Interpreters),
Using different offline and online Python IDE,
Interacting with Python programs

2. Data types:
Numeric, Boolean, Strings, Lists, Tuples, Sets, Dictionary

3. Variables:
Declaration and initialization

4. Simple Statements:
Taking inputs from user, Displaying outputs

5. Other concepts:
Operators, Expressions, Indentation, Comments, Casting

Side 1
BBS GROUP OF INSTITUTIONS

1. Introduction

Side 2
BBS GROUP OF INSTITUTIONS

1. Introduction

Key features

• It is the most widely used, high-level, general-purpose, multi-purpose, and interpreted programming language.
• There are two major Python versions: Python 2 and Python 3 (the latest version is 3.7.1, we can call it Python
3).
• It was created by Guido Van Rossum, and released in 1991. Python 3.0 was released in 2008.
• It is developed under an OSI-approved open-source license, making it freely usable and distributable, even for
commercial use.
• Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). It is portable across operating
systems.
• Python has a simple syntax similar to the English language.
• Python runs on an interpreter system, meaning that code can be executed as soon as it is written.
• Python can be treated in a procedural, object-orientated, or functional way.
• Its design philosophy emphasizes code readability.
• Its syntax allows programmers to express concepts in fewer lines of code.
• The best way we learn anything is by practice and exercise questions.
• Python uses new lines to complete a command instead of semicolons or parentheses.
• Python uses indentation through whitespace instead of curly-brackets, to define the scope of loops, functions,
and classes.
• Python can connect to database systems. It can also read and modify files.
• It is well suited for beginners and experienced programmers with other programming languages like C++
and Java.
• The biggest strength of Python is the huge collection of standard libraries that can be required in many
applications (NumPy for numerical calculations, Pandas for data analytics, etc).
• you can download it for free from the following website: https://www.python.org/
Side 3
BBS GROUP OF INSTITUTIONS

1. Introduction

Applications of Python

• Python can be used on a server to create web applications.


• It can be used to create GUI based desktop applications(Games, Scientific and Business Applications).
• It is also used to create test frameworks and multimedia applications.
• It is used to develop operating systems and programming language.
• It can be used to handle image processing, text processing and natural language processing.
• It can be used to create programs for machine learning, deep learning, data science, big data and data
analytics applications.
• It can also perform complex mathematics along with all cutting edge technology in software industry.

Organizations and tech-giant companies using Python :


1) Google(Components of Google spider and Search Engine)
2) Yahoo(Maps)
3) YouTube
4) Mozilla
5) Dropbox
6) Microsoft
7) Cisco
8) Spotify
9) Quora
10)Instagra
m
11)Amazon
12)Facebook
13)Uber etc. Side 4
BBS GROUP OF INSTITUTIONS

1. Introduction

Python Editors and Interpreters

• Python is interpreted language i.e it’s not compiled and the


interpreter will
check the code line by line.
• Code can be written in a text editor with .py extension and then it can
be put into the
python interpreter for execution.

Side 5
BBS GROUP OF INSTITUTIONS

1. Introduction

Using different offline and online Python IDE

Offline Thonny, Pycharm, Spyder, IDLE, Netbeans or Eclipse


IDE: PyDev etc. https://www.w3schools.com/python/
Online https://www.w3resource.com/python/python-
IDE: tutorial.php
https://www.geeksforgeeks.org/python-
programming-language/

https://www.tutorialspoint.com/execute_python_onli
ne.php

Side 6
BBS GROUP OF INSTITUTIONS

1. Introduction

Interacting with Python programs

Side 7
BBS GROUP OF INSTITUTIONS

2. Datatypes

Side 8
BBS GROUP OF INSTITUTIONS
2. Data types

Python is a dynamically typed language(No need to mention data type based on value
assigned, it takes data type)

You can get the data type of any object by using the type( ) function

Side 9
BBS GROUP OF INSTITUTIONS

2. Data types
Numeric Type: int, float, complex

Side 10
BBS GROUP OF INSTITUTIONS

2. Data types
Boolean Type: bool

Side 11
BBS GROUP OF INSTITUTIONS

2. Data types
Text Type (Strings): str

We can assign a string to a variable as below:


a = "Hello“

We can assign a multiline string to a variable by using three single or three double quotes
as below:
(Note: in the result, the line breaks are inserted at the same position as in the
code.): a = ’‘’Hi everyone,
This is Python Class.’‘’
a = ”””Hi everyone,
This is Python Class.”””

To concatenate, or combine, two strings we can use the + operator as below:


a = "Hello"
b = “Class"
c=a+""+b

We cannot combine strings and numbers like this:


age = 30
txt = "My name is XYZ, I am " + age

Side 12
BBS GROUP OF INSTITUTIONS

2. Data types
Text Type (Strings): str …continued

Side 13
BBS GROUP OF INSTITUTIONS
2. Data types
Text Type (Strings): str …continued

Side 14
BBS GROUP OF INSTITUTIONS
2. Data types
Sequence Type: list
A list is a collection that is ordered, indexed, and changeable. It allows duplicate
members.
Lists are written with square brackets [ ].
We can access list items by referring to the index number, inside square brackets.

Side 15
BBS GROUP OF INSTITUTIONS

2. Data types
Sequence Type: list …continued

Side 16
BBS GROUP OF INSTITUTIONS

2. Data types
Sequence Type: tuple
A tuple is a collection that is ordered, indexed, and unchangeable. It
allows duplicate members.
Tuples are written with round brackets ( ).
We can access tuple items by referring to the index number, inside square
brackets.

Side 17
BBS GROUP OF INSTITUTIONS

2. Data types
Sequence Type: tuple …continued

Side 18
BBS GROUP OF INSTITUTIONS

2. Data types
Set Type: set
Set is a collection which is unordered, unindexed and
unchangeable. It does not allow duplicate members.
Sets are written with curly brackets { }.

Side 19
BBS GROUP OF INSTITUTIONS
2. Data types
Mapping Type (Dictionary): dict
Dictionary is a collection which is unordered, indexed and
changeable. It does not allow duplicate members.
Dictionaries are written with curly brackets, and they have keys
and values. We can access the items of a dictionary by referring to
its key name, inside square brackets.

Side 20
BBS GROUP OF INSTITUTIONS

3. Variables

Side 21
BBS GROUP OF INSTITUTIONS
3. Variables
Declaration and initialization

Variables are containers for storing data


values. Python has no command for
declaring a variable.
A variable is created the moment you first assign a value to it.

Rules for Python variables:


v A variable name must start with a letter or the underscore character
v A variable name cannot start with a number
v A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9,
and _ )
v Variable names are case-sensitive (age, Age and AGE are three different variables)

Variables do not need to be declared with any particular type and can even
change type after they have been set.

String variables can be declared either by using single or double

quotes. We can assign values to multiple variables in one line.

We can assign the same value to multiple variables in one line.

Side 22
BBS GROUP OF INSTITUTIONS
3. Variables
Declaration and initialization …continued

Side 23
BBS GROUP OF INSTITUTIONS

4. Simple Statements

Side 24
BBS GROUP OF INSTITUTIONS
4. Simple Statements
Taking inputs from user

Python 3.6 uses the input( ) method while Python 2.7 uses the
raw_input( ) method.

Side 25
BBS GROUP OF INSTITUTIONS

4. Simple Statements
Displaying outputs

print statement is often used to output variables.


To concatenate two or more strings or string variables the + character is
used. For numbers, the + character works as a mathematical operator.
If you try to combine a string and a number, Python will give you an
error.

Side 26
BBS GROUP OF INSTITUTIONS

5. Other Concepts

Side 27
BBS GROUP OF INSTITUTIONS

5. Other Concepts

Operators and Expressions

•Arithmetic operators (+, -, *, /, %, **, //)


•Assignment operators (=, +=, -=, *=, /=, %=, **=, //=, &=, |=, <<=,
>>=, ^=)
•Comparison operators (==, !=, <, >, <=, >=)
•Logical operators (and, or, not)
•Identity operators (is, is not)
•Membership operators (in, not in)
•Bitwise operators (&, |, ^, ~, <<, >>)

Side 28
BBS GROUP OF INSTITUTIONS
5. Other Concepts
Operators and Expressions …continued

Arithmetic operators
** is used for Exponentiation and // is used for
Floor division.

Side 29
BBS GROUP OF INSTITUTIONS

5. Other Concepts
Operators and Expressions …continued

Logical operators

Side 30
BBS GROUP OF INSTITUTIONS

5. Other Concepts
Operators and Expressions …continued

Identity operators

Side 31
BBS GROUP OF INSTITUTIONS

5. Other Concepts
Operators and Expressions …continued

Identity operators

Side 32
BBS GROUP OF INSTITUTIONS

5. Other Concepts
Operators and Expressions …continued

Membership operators

Side 33
BBS GROUP OF INSTITUTIONS
5. Other Concepts
Indentation

Indentation refers to the spaces at the beginning of a code line.

Where in other programming languages the indentation in code is for readability


only, the indentation in Python is very important.

Python uses indentation to indicate a block of code. Other languages often use
curly- brackets for this purpose.

Python will give you an error if you skip the indentation.

The number of spaces is up to you as a programmer, but it has to be at least one.

You have to use same number of spaces in the same block of code, otherwise
Python
will give you an error.

Correct Example:
if 5 > 2:
print("Five is greater
than two!") if 5 > 2:
print("Five is greater than two!")
Side 34
BBS GROUP OF INSTITUTIONS

5. Other Concepts
Comments

Comments start with a #, and Python will ignore them.

Python does not really have a syntax for multi-line

comments. To add a multiline comment you could

insert a # for each line.

Since Python will ignore string literals that are not assigned to a
variable, you can add a multiline string (triple quotes) in your
code, and place your comment inside it.

Side 35
BBS GROUP OF INSTITUTIONS

Queries ?

Side 36

You might also like