Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Day 1 Python

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Day 1

Fundamental Python
By
Dr. Chit Su Hlaing
Why Python
• Python is simple to use, but it is a real programming language,
offering much more structure and support for large programs
than C and other languages.
• Python is a very-high-level language and it has high-level data
types built in, such as flexible arrays and dictionaries.
• Because of its more general data types Python is applicable to a
much larger problem domains.
• Python enables programs to be written compactly and readably.
Programs written in Python are typically much shorter than
equivalent C, C++, or Java programs.
How python program work ?
Run Python in Command Prompt (Cmd) Window
Interactive Mode (On Shell) – Python
Interpreter
• In this mode it prompts
• for the next command with the primary prompt, usually three
greater-than signs (>>>);
• for continuation lines it prompts with the secondary prompt, by
default three dots (...).
An Informal Introduction
to Python
Number Calculation
Using Python as a Calculator
• The interpreter acts as a simple calculator: you can type an
expression at it and it will write the value. Expression syntax is
straightforward: the operators +, -, * and / can be used to
perform arithmetic; parentheses (()) can be used for grouping.
Using Python as a Calculator
• Division (/) always returns a float. To do floor division and get an
integer result you can use the // operator; to calculate the
remainder you can use %:
Using Python as a Calculator
• With Python, it is possible to use the ** operator to calculate
powers
Using Python as a Calculator
• The equal sign (=) is used to assign a value to a variable.
Text Processing
• Text can be enclosed in single quotes ('...') or double quotes ("...")
with the same result.
Text Processing
• To quote a quote, we need to “escape” it,
• by preceding it with \.
• By using the other type of quotation marks:
\n and raw Stering (r)
Text Processing
• String literals can span multiple lines. One way is using triple-quotes:
"""...""" or '''...'''.

You might also like