0% found this document useful (0 votes)
36 views28 pages

Starting With Python: Click To Edit Master Title Style

The document provides an introduction to Python programming. It discusses what Python is, how it uses an interpreter and shell, common syntax like indentation and comments. It also covers Python data types like integers, floats, strings, lists, tuples and dictionaries. Variables are assigned using names and the = operator. Data types can be mutable like lists or immutable like integers. Mathematical operators can perform operations on variables.

Uploaded by

Jean Rona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views28 pages

Starting With Python: Click To Edit Master Title Style

The document provides an introduction to Python programming. It discusses what Python is, how it uses an interpreter and shell, common syntax like indentation and comments. It also covers Python data types like integers, floats, strings, lists, tuples and dictionaries. Variables are assigned using names and the = operator. Data types can be mutable like lists or immutable like integers. Mathematical operators can perform operations on variables.

Uploaded by

Jean Rona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Click to edit Master title style

Starting with
Python
Module 1

1
Click to edit Master title style
Outline:

• Introduction to Python
• The print() Function
• Data Types
• Type Casting

2
Click to
What edit Master title style
is python?

• Python is an interpreted, object-oriented, high-level programming


language with dynamic semantics.
• Its high-level built in data structures, combined with dynamic
typing and dynamic binding, make it very attractive for Rapid
Application Development
• Python's simple, easy to learn syntax emphasizes readability and
therefore reduces the cost of program maintenance.

3
Click to
What edit Master title style
is python?

• Python supports modules and packages, which encourages


program modularity and code reuse.
• The Python interpreter and the extensive standard library are
freely distributed.

4
Click to Interpreter
Python edit Master title style

• The Python interpreter is a virtual machine, meaning that it is


software that emulates a physical computer
• It will read each line and doesn’t create an immediate object code
like the compiler does
• Python interpreter takes an interactive command and executes it
• All lines of source code are completed (translated) one line at a
time.
• Compilation of the source codes occur through the translation
process.

5
Click to Shell
Python edit Master title style

• Python provides a Python Shell, which is used to execute a single


Python command and display the result.
• It is also known as REPL (Read, Evaluate, Print, Loop), where it
reads the command, evaluates the command, prints the result,
and loop it back to read the command again.

6
Click to Code
Python edit Master
Editorstitle style

• IDLE (Integrated Development and Learning Environment) is an


integrated development environment (IDE) for Python
• IDLE can be used to execute a single statement just like Python
Shell and also to create, modify, and execute Python scripts
• IDLE provides a fully-featured text editor to create Python script
that includes features like syntax highlighting, autocompletion,
and smart indent
• It also has a debugger with stepping and breakpoints features

7
Click to Common
Python edit Master title style
Syntax

• NEWLINE character “\n”


• Backslash [/] to Join Statement Span over Multiple Lines
• Multiple Statements in Single Line
• Semicolon [;] to Separate Multiple Statements in a Single Line

8
Click to editin
Indentation Master title style
Python

• Leading space or tab at the beginning of the line is considered as


indentation level of the line, which is used to determine the group
of statements.
• Statements with the same level of indentation considered as a
group or block
• Python uses indentation (a space or a tab) to denote a block of
statements

9
Click to editRules
Indentation Master title style

• Use the colon : to start a block and press Enter


• All the lines in a block must use the same indentation, either
space or a tab
• Python recommends four spaces as indentation to make the code
more readable
• Do not mix space and tab in the same block
• A block can have inner blocks with next level indentation

10
Click to edit[01]
Simulation Master title style

11
Click to editinMaster
Comments Pythontitle style

• In a Python script, the symbol # indicates the start of a comment


line
• It is effective till the end of the line in the editor
• In Python, there is no provision to write multi-line comments, or a
block comment
• For multi-line comments, each line should have the # symbol at
the start
• A triple quoted multi-line string is also treated as a comment if it is
not a docstring of the function or the class

12
Clicktype()
The to editFunction
Master title style

• Objects are Python's abstraction for data


• In Python, data are represented by objects or by relations
between objects
• Use the type() function to get the class name of an object
• All values are actually an object of a class depending upon the
value.

13
Click to edit
Variables Master title style
Assignment

• Variables in Python are names given to objects, so that it


becomes easy to refer a value
• A variable points to an object
• A literal value is assigned to a variable using the = operator where
the left side should be the name of a variable, and the right side
should be a value
• Different operations can be performed on variables using various
operators based on the type of variables, for example, the +
operator sums up two int variables, whereas it concatenates two
string type variables

14
Click to Conventions
Naming edit Master title style

Any suitable identifier can be used as a name of a variable, based on the following rules:

1. The name of the variable should start with either an alphabet letter (lower or upper case)
or an underscore (_), but it cannot start with a digit.
2. More than one alpha-numeric characters or underscores may follow.
3. The variable name can consist of alphabet letter(s), number(s) and underscore(s) only.
1. For example, myVar, MyVar, _myVar, MyVar123 are valid variable names, but m*var, my-var, 1myVar
are invalid variable names.

4. Variable names in Python are case sensitive


5. Variable names cannot be a reserved keywords in Python.
15
Click to Data
Python edit Types
Master title style

Data types are the classification or categorization of data items


• Scalar
• Sequence
• Mapping
• Set
• Mutable and Immutable

16
Click toData
Scalar editTypes
Master title style
• int: Positive or negative whole numbers (without a fractional part)
e.g. -10, 10, 456, 4654654.
• float: Any real number with a floating-point representation in which
a fractional component is denoted by a decimal symbol or
scientific notation e.g. 1.23, 3.4556789e2.
• complex: A number with a real and imaginary component
represented as x + 2y.
• bool: Data with one of two built-in values True or False. Notice
that 'T' and 'F' are capital. true and false are not valid booleans
and Python will throw an error for them.
• None: The None represents the null object in Python. A None is
returned by functions that don't explicitly return a value.

17
Click to edit
Sequence Master
Data Typestitle style

A sequence is an ordered collection of similar or different data types. Python


has the following built-in sequence data types:

• String: A string value is a collection of one or more characters put in single,


double or triple quotes.
• List: A list object is an ordered collection of one or more data items, not
necessarily of the same type, put in square brackets.
• Tuple: A Tuple object is an ordered collection of one or more data items, not
necessarily of the same type, put in parentheses.
18
Click to edit
Mapping DataMaster
Type title style

• Dictionary: A dictionary Dict() object is an unordered collection of


data in a key:value pair form.
• A collection of such pairs is enclosed in curly brackets.
• For example: {1:"Steve", 2:"Bill", 3:"Ram", 4: "Farha"}

19
Click to edit
Mutable and Master titleData
Immutable styleTypes

• Numbers, strings, and Tuples are immutable, which means their


contents can't be altered after creation.

• List or Dictionary object can be modified. It is possible to add,


delete, insert, and rearrange items in a list or dictionary. Hence,
they are mutable objects.

20
Click to edit Master
Mathematical title style
Operators

21
Click to edit
Objects Master title style
Identity

• Each object in Python has an id


• It is the object's address in memory represented by an integer
value
• The id() function returns the id of the specified object where it is
stored
• An id will be changed if a variable changed to different value
• Multiple variables assigned to the same literal value will have the
same id

22
Click to edit
Multiple Master
Variable title style
Assignment

• You can declare multiple variables and assign values to each


variable in a single statement separated by a comma (,)
• Assignment of values to variables must be in the same order in
they declared

23
Click to edit[02]
Simulation Master title style

24
Click to
Type edit Master title style
Casting

• There may be times when you want to specify a type on to a


variable
• This can be done with casting
• Python is an object-orientated language, and as such it uses
classes to define data types, including its primitive types.

25
Click to
Type edit Master title style
Casting

• Casting in python is therefore done using constructor functions:

• int() - constructs an integer number from an integer literal, a float literal


(by removing all decimals), or a string literal (providing the string
represents a whole number)
• float() - constructs a float number from an integer literal, a float literal or
a string literal (providing the string represents a float or an integer)
• str() - constructs a string from a wide variety of data types, including
strings, integer literals and float literals

26
Click to Functions
Built-in edit Master title style

A numeric object of one type can be converted in another type using the
following functions:

27
Click to edit[03]
Simulation Master title style

28

You might also like