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

Python Basics

Uploaded by

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

Python Basics

Uploaded by

Pawan kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PytHon Basics

By - Tarun Kumar
(ekmrtrn)
Contents

• Python Introduction • Python Flow Control


• Definition and Installation • If-Else
• Keywords • For Loop
• Statements and Comments • While Loop
• Python Variables • Break and Continue
• Python Data Types • Pass
• Python Type Conversion
• Python I/O and Import
• Python Operators
Contents

• Python Functions • Python DataTypes


• Functions • Numbers
• Function Argument • List
• Recursion • Tuple
• Global and local • String
• Global Keyword • Set
• Python Modules • Dictionary
• Python Packages
Contents

• Python Files
• File Operation
• Directory
• Exception
• Exception Handling

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 4
Python Introduction

• Python is a cross-platform programming language, which means that it


can run on multiple platforms like Windows, macOS, Linux, and has
even been ported to the Java and .NET virtual machines. It is free and
open-source.
• Even though most of today's Linux and Mac have Python pre-installed
in it, the version might be out-of-date. So, it is always a good idea to
install the most current version.
Python Introduction
Python Keywords :

• Keywords are the reserved words in Python.


• We cannot use a keyword as a variable name, function name or any
other identifier. They are used to define the syntax and structure of the
Python language.

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 6
Python Introduction
Python Statement :
• Instructions that a Python interpreter can execute are called statements.
For example, a = 1 is an assignment statement. if statement, for
statement, while statement, etc. are other kinds of statements which will
be discussed later.

Python Indentation :

• Most of the programming languages like C, C++, and Java use braces
{ } to define a block of code. Python, however, uses indentation.
• A code block (body of a function, loop etc.) starts with indentation and
ends with the first unindented line. The amount of indentation is up to
you, but it must be consistent throughout that block.
• Generally, four whitespaces are used for indentation and are preferred
over tabs.

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 7
Python Introduction
Python Variables :
• A variable is a named location used to store data in the memory. It is
helpful to think of variables as a container that holds data that can be
changed later in the program. For example, number = 22

Rules for Variable and constant naming conventions :

• Constant and variable names should have a combination of letters in


lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an
underscore (_).
• Create a name that makes sense. For example, vowel makes more
sense than v.
• If you want to create a variable name having two words, use underscore
to separate them.
• Use capital letters possible to declare a constant.
• Never use special symbols like !, @, #, $, %, etc
• Don't start a variable name with a digit.
Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 8
Python Introduction
Literals
• Literal is a raw data given in a variable or constant. In Python, there are
various types of literals they are as follows:
• Numeric literals
• String Literals
• Boolean Literals
Python Datatypes
• Every value in Python has a datatype. Since everything is an object in
Python programming, data types are actually classes and variables are
instance (object) of these classes.
• There are various data types in Python. Some of the important types are
listed below.

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 9
Python Introduction
Python 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
• Declaring a list is pretty straight forward. Items separated by commas are
enclosed within brackets [ ].
Python Tuples
• 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.

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 10
Python Introduction
Python Strings
• String is sequence of Unicode characters. We can use single quotes or
double quotes to represent strings. Multi-line strings can be denoted
using triple quotes, ’ ’ ’ or “ “ “

Python Tuples
• 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.

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 11
Python Introduction
Python Set
• Set is an unordered collection of unique items. Set is defined by values
separated by comma inside braces { } . Items in a set are not ordered.

Python Dictionary
• Dictionary is an unordered collection of key-value pairs.
• It is generally used when we have a huge amount of data. Dictionaries are
optimized for retrieving data. We must know the key to retrieve the value.
• In Python, dictionaries are defined within braces {} with each item being a
pair in the form key:value. Key and Value can be of any type.

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 12
Python Introduction
Python Output using print() function
• We can use the print() function to output data to the standard output
device(screen).

Python Import
• A module is a file containing Python definitions and statements. Python
Modules have a filename and end with the extension .py
• Definitions inside a module can be imported to another module or the
interactive interpreter in Python.We use the import keyword to do this.

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 13
Python Introduction
Python Operators
• Operators are special symbols in Python that carry out arithmetic or
logical computation. The value that the operator operates on is called the
operand.
• Types of Operators:
• Arithmetic Operators
• Comparison Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Special Operators
• Identity Operators
• Membership Operators

Official Ericsson Pow erpoint Template | Ericsson Internal | LME-11:002291 Uen, Rev A | 2011-06-21 | Page 14

You might also like