python好多天没有碰了,在公司整理WIKI平台。把《高性能MySQL》这本书做了一个梳理,完成PDF文档,参与线下oracle 大会 从中学习到不少东西。整个体系以及格局 以及未来的发展。
好了,下面对python 第一天的内容 进行一个回顾,并开始着手 开展python。
一个简单的小例子。
name = ['alex','jack','kevin'] age = '29' for i in name: print 'my name is '+ i + ',and I am ' + age + 'years old!'
输出内容:
my name is alex,and I am 29years old!
my name is jack,and I am 29years old!
my name is kevin,and I am 29years old!
str与int类型交互 转化类型。
>>> print int(str(age)) //转为int类型
30
>>> print type(str(age)) //类型为str
<type 'str'>
>>> type(str(age))
<type 'str'>
>>> user_input = raw_input('input your lucky num:') //如果不转为int类型与数字交互会报错
input your lucky num:9
>>> user_input + 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
>>> int(user_input) + 0 //转换后的形式
9
#coding:utf-8 name = raw_input('what is your name?:') age = raw_input('how old are you?:') job = raw_input('what is your job?:') msg = """ Information of %s as below: Name : \033[42;1m%s \033[0m Age : %s Job : %s """ %(name,name,age,job) if int(age) >= 50: print "you are too old,you can only work" elif int (age) >=30: print "you are too old, you can only work for ..." elif int (age) >20: print "you wei cheng nian" else: print "old your xia" print msg
结果:
what is your name?:madon
how old are you?:22
what is your job?:it
you wei cheng nian
Information of madon as below:
Name : madon
Age : 22
Job : it
本文出自 “晴空” 博客,谢绝转载!