python 编程从入门到实践 第二章 变量和简单数据类型

-- 变量 
message = "hello python word"
print(message)

-- 练习 

vi simple_message.py
#!/usr/bin/python3.4
message = "hello python crash cousor reader!"
print(message)

vi simple_messages.py
messages = "AAAAAA  hello python crash cousor reader!"
print(messages)
messages = "BBBBBBB  hello python crash cousor reader!"
print(messages)

-- 首字母大写 全部转换为大写 小写
name = "habby yang"
print(name.title())
print(name.upper())
print(name.lower())

-- 连接字符串
fisrt_name = "king"
middle_name = "of"
last_name = "pop"
full_name = fisrt_name + " " + middle_name + " " + last_name
print(full_name)

-- \t 制表符 \n 换行
print("python")
print("\tpython")
print("\npython")
print("\npython\n")
print("languages:\n\tPython\n\tC\n\tJavascript")

-- 删除空白 rstrip()  只能去除开头和结尾的空白  左侧 lstrip() 右侧 rstrip()
habby="         aaa bbb ccc      "
habby.lstrip()
habby.rstrip()
habby.lstrip().rstrip()


-- 下面的语句在 Python 3 不能执行 只能在 Python 2 中执行  因为 Python3 将 print() 作为一个函数使用 不能直接打印内容 但是  name.print() 也是不能成功执行的
print "habby"
name = 'habby_yang'
name.print()


name = "habby yang"
world1 = "hello" + " " + name + ",would you like to learn some python today?"
world2 = "hello" + " " + name.title() + ",would you like to learn some python today?"
world3 = "hello" + " " + name.upper() + ",would you like to learn some python today?"
world4 = "hello" + " " + name.lower() + ",would you like to learn some python today?"
print(world1)
print(world2)
print(world3)
print(world4)

print("\n",world1,"\n",world2,"\n",world3,"\n",world4)

>>> print("\n",world1,"\n",world2,"\n",world3,"\n",world4)

 hello habby yang,would you like to learn some python today?
 hello Habby Yang,would you like to learn some python today?
 hello HABBY YANG,would you like to learn some python today?
 hello habby yang,would you like to learn some python today?

myworld = 'I said,"my action brings my confidence!"'
print(myworld)

-- 数字的字符转换函数
age = 23
message = "happy " + str(age) + "rd BirsthDay!"
print(message)


print(4+4)
print(12-4)
print(2*4)
print(24/3)

age =  31
message = "happy,you are  " + str(age) + " years old!"
print(message)







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值