You are on page 1of 13

Python Basics and

Web Application
Development Tips
Jiannan Liu (Johnny)
Outline
—  Why python
—  Basic expressions
—  Data types
—  Build-in functions
—  Loop and condition

—  Web application development tips


Why Python
—  Easy to read and learn.
—  Support multiple systems and platforms.
—  Quick development with less code.
—  Large amount of resources.
—  …
There seems to be widespread agreement that developing
Python applications is about five to 10 times faster than
developing the same application in Java. Time savings are even
greater when compareåd to C/C++.

--Dan Sahfer
Basic Expressions
—  + - * / addition, subtraction/negation, multiplication, division

—  ** exponential
Eamples:
1.  1+3*5=16
2.  2**3=8
3.  a=3
a+=a
By using from math import *, you can use methods like:

abs(), sqrt(), log(), max(), min()…

For more methods available, you can refer to:


https://docs.python.org/2/library/math.html
Data Types
—  Numeric
1.  int: Integers; equivalent to C longs in Python 2.x,
non-limited length in Python 3.x
2.  float: Floating-Point numbers, equivalent to C
doubles
3.  complex: Complex Numbers
You can check the data type by type() command.

Example:
a=2.0
a=int(a)
b=2
b=float(b)
type(a)
type(a)
type(b)
type(b)
Data Types
—  Sequences
1.  str: String; represented as a sequence of 8-bit characters
in Python 2.x, but as a sequence of Unicode charactersin
Python 3.x (Immutable)
2.  bytes: a sequence of integers in the range of 0-255; only
available in Python 3.x(Immutable)
3.  byte array: like bytes, but mutable; only available in
Python 3.x
4.  list
5.  tuple(Immutable) a=‘This is DB class’
b=b‘This is DB class’
c=[‘This is DB class’]
d=(‘This is DB class’)
Data Types
—  Mappings
1.  dict: Python dictionaries, also called hashmaps or
associative arrays, which means that an element of
the list is associated with a definition, rather like a
Map in Java

fruit={'apple': 'Yes', 'banana': 'No'}

fruit_numb={'apple': 3, 'banana': 0}
Build-in functions
—  Functions that are always available in Python.
max(), min(), sorted(), list(), tuple(),
print(), range(), len()…
More build in functions:
https://docs.python.org/3/library/functions.html#func-set

a=[5,3,2,4,1,0] a=‘database’
a=sorted(a) a=list(a)
print(a) a_length=len(a)
[0, 1, 2, 3, 4, 5]
Loop and Condition
—  Indentation(for space or one tab) is used to keep
code structure.

For loop: While loop:

For VariableName in GroupofValues: while Condition:


Statement Statement
Loop and Condition
Logic expression:

If/else:
if condition:
if condition:
statement
statement
else: or elif condition:
statement
statement
elif condition:
statement
Loop and Condition
Examples:
Web Application
Development Tips
—  Develop tools available in most of browsers
—  Be familiar with command line commands

Mac:
ls, cd, mkdir, touch, open, rm…

Windows:
ls, dir, cmd, mkdir, rmdir…
Thank you!

You might also like