了解python文件结构,
保存成one.py
另外pyc, pyo文件
pyc编译执行的文件
pyo编译优化后的文件
掌握python变量和常量
推荐第一门语言为python
变量:c语言是强类型
变量的命名
有字母、数字
数字不能开头
first= 100
print(first)
id(first)
变量的类型取决于数据
name = 'milo'
print(name)
id(name)
写个四则运算器
算数运算符(加减乘除)
5/2 = 2
5.0/2 = 2.5
5//2 = 2 整除
赋值运算符
a = 3
b = 5
c = a+b
关系运算符(结果为布尔值)
x = 5
x >0 and x<10
NameError: name 'true' is not define
变量没有定义
数据类型
数字、字符串、列表、元组和字典、布尔
a = 100
b = 'hello'
c = '100' 字符串
id(a)
id(c)
a == c result: False
查看数据类型
type(a)
<type 'int'>
q = 10000000000000
type(q)
<type 'long'> 长整形
l = 10L (长整形)
type(l)
<type 'long'>
f = 1.1
type(f)
<type 'float'>
say = "let's go"
print(say)
双引号和单引号,没有太大区别
使用转义"\"来处理单双引号问题
"\n" 换行
"\t" 缩进
docstring使用
s = """ tom:"let's go"
>>> s = """ tom:"let's go"
... jerry:"ok"
... """
>>> print s
序列
>>>s2 = 'abcdefg'
>>>print s2[0]
'a'
>>>s2[2]
'c'
>>>s2[-1] 倒数第一个
'g'
字符串小技巧
>>> x = input()
10
>>> y = input()
20
>>> z = x+y
>>> z
30
练习题
对输入的2个数字加减乘除运算
保存成one.py
另外pyc, pyo文件
pyc编译执行的文件
pyo编译优化后的文件
掌握python变量和常量
推荐第一门语言为python
变量:c语言是强类型
变量的命名
有字母、数字
数字不能开头
first= 100
print(first)
id(first)
变量的类型取决于数据
name = 'milo'
print(name)
id(name)
写个四则运算器
from __future__ import division
import sys
running = True
while running:
try:
t = int(raw_input())
p = int(raw_input())
except EOFError:
break
print('operator + result\n', t+p)
print('operator - result\n', t-p)
print('operator * result\n', t*p)
print('operator / result\n', t/p)
[code="java"]
[/code]算数运算符(加减乘除)
5/2 = 2
5.0/2 = 2.5
5//2 = 2 整除
赋值运算符
a = 3
b = 5
c = a+b
关系运算符(结果为布尔值)
x = 5
x >0 and x<10
NameError: name 'true' is not define
变量没有定义
数据类型
数字、字符串、列表、元组和字典、布尔
a = 100
b = 'hello'
c = '100' 字符串
id(a)
id(c)
a == c result: False
查看数据类型
type(a)
<type 'int'>
q = 10000000000000
type(q)
<type 'long'> 长整形
l = 10L (长整形)
type(l)
<type 'long'>
f = 1.1
type(f)
<type 'float'>
say = "let's go"
print(say)
双引号和单引号,没有太大区别
使用转义"\"来处理单双引号问题
"\n" 换行
"\t" 缩进
docstring使用
s = """ tom:"let's go"
>>> s = """ tom:"let's go"
... jerry:"ok"
... """
>>> print s
序列
>>>s2 = 'abcdefg'
>>>print s2[0]
'a'
>>>s2[2]
'c'
>>>s2[-1] 倒数第一个
'g'
字符串小技巧
>>> x = input()
10
>>> y = input()
20
>>> z = x+y
>>> z
30
练习题
对输入的2个数字加减乘除运算
>>> x = input()
10
>>> y = input()
20
>>> z = x+y
>>> z
30
>>> z = x -y
>>> z
-10
>>> z = x *y
>>> z
200
>>> z = x / y
>>> z
0