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())

猜你喜欢

转载自blog.csdn.net/qq_42113763/article/details/87905990