Python 学习-- (Python编程:从入门到实践)

1.字符串

定义:字符串就是一系列字符。在Python中用引号括起来的都是字符串

注意:引号可以是双引号,也可以是单引号,这种灵活性让你能够在字符串中包含引号和撇号

Exercise:

message_double = "this is double quotation marks demo "
message_single = 'this is single quotation mark demo'
print(message_double)
print(message_single)

需谨记:创建Python文件需要记得.py

Exercise 

exercise_1 = ' i told my friend ,"python is my favorite language " '
exercise_2 = "the language 'Python' is named after Monty Python,not the snake"
exercise_3 = "one of python's strengths is its diverse and support community"
print(exercise_1)
print(exercise_2)
print(exercise_3)

知识点:

1.Python使用加号(+ )来合并字符串

first_name = "yu"
last_name = 'yang'
full_name = first_name + " " + last_name
print(full_name)

2.制表符 \t  

3.换行符 \n

4.去除空白  rstrip() 【右去除】 lstrip()【左去除】 strip() 【同时剔除】

4.1只能去除尾部空白,无法去除前面空白

4.2删除的变量需要存回变量中,才能保存。rstrip()不会保存修改后的变量

message = '   python '
print(message)
print(message.rstrip())

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值