CJKV Information Processing
Ken Lunde
O'Reilly
2009912 pages
Excellent reference forCJKV issues such as
Unicode GB2312,GBK,GB18030 etc.
Who is Guido van Rossum?
Guido van Rossum,1980s
吉多·范·罗苏姆(Jí duō·fàn·luō sū mǔ)
He is fromNetherlands(荷兰)
What does it mean for programs to be ‘portable’?
Portable - develop on Linux, use on Windows, Mac etc and so on
What are the two versions of Python?
Python 2.x(usually 2.7)
The traditional form
Stayed the same for many years
Had a few problems
Python 3.x
The newer form
Similar to 2.x but some differences
What character encoding should be used for Python programs?
UTF-8 Encoding
What is a comment? What are the two types of comment in Python?
A comment is something which is ignored
Use comments to add notes to explain
how the program works
First form starts with #
Second form is multiple lines
Starts and ends with""" or '''
Here is the """ form(three double quotes ")
Second form cont.
Here is the ''' form(three single quotes ')
What is the syntax of a Python variable name?
A variable name:
Can contain letters a-z
Can contain letters A-Z
Can contain digits 0-9
Can contain underscores _
However:
Cannot start with a digit
Cannot contain any other types of letter
e.g. ‘%’, ‘^’ etc cannot be used in
variable names
Some people use ‘Camel Case’ to show words in a long variable name:
thisIsAVariableName
Other people use underscores instead:
this_is_a_variable_name
Python allows both forms.
What is Camel Case?
What is the difference between a declaration (e.g. x = 1) and an assignment (e.g. x = 1 )?
a declaration(e.g. x =1) decalre variable x and assign a value
an assignment(e.g. x =1) x already exist, change its value
What is the difference between / and // ?
/ division
// Integer division Rounds down to nearest whole number
x =5; y =2;
x/y
2.5
x//y2
What is the difference between // and %?
% Modulus模运算符 Remainder after integer division
x =5; y =2;
x//y2
x%y
1
What does x ** 2 mean?
** Exponent 指数算子
x的二次方
The second power of x
What does x += 1 mean?
Combine Operator with Assignment 赋值与运算的结合
x = x +1A shorter method is available:
x +=11. Get value of x
2. Add one to it
3. Assign newvalue to x
Similarly with*=,-=,/=
Also works with//, %, **
What is the largest integer in Python?
2的63次方-1
What is the longest string in Python?
A Python string is allowed to be very long
You can use \ to continue onto the next line
You can read a whole file into a string if you wish.
In something like: university = “Northwest” + “University” + “1902”
‘NorthwestUniversity 1902’
What is the purpose of the backslash \ ?
We can join any number of strings
Note the use of \ to continue the line
Without \, we get an error
What does this do: ‘exchange rate is %3.1f’ % (9.09)
'exchange rate is 9.1'
What is the difference between “1902” and 1902 ?
“1902” is a string
1902 is an integer
What is type casting in Python? Give an example using the str() function
s1 ="Northwest was founded in "
s2 = s1 +str(1902)
s2
'Northwest was founded in 1902'
What is CJKV?CJKV Information ProcessingKen LundeO'Reilly2009912 pagesExcellent reference for CJKV issues such asUnicode GB2312, GBK, GB18030 etc.Who is Guido van Rossum?Guido van Rossu...