码农之家
这篇文章主要知识点是关于Python编程,从入门到实践,变量和简单数据类型,Python编程:从入门到实践,《Python编程:从入门到实践》第九章:类 Python编程实现输入某年某月某日计算出这一天是该年第几天的方法 18天学习《python编程:从入门到实践》心得笔记 《Python编程:从入门到实践》第五章:if语句 《Python编程:从入门到实践》第四章:操作列表 的内容,如果大家想对相关知识点有系统深入的学习,可以参阅以下电子书
举例:
>>> message = "Hello,Python!" >>> print (message) Hello,Python!
这里的message就是变量,可以理解成变量就是一个存储数据的容器。在程序中可随时修改变量的值,而python将始终记录变量的最新值。
字符串就是一系列字符,在python中用单引号或者双引号括起来。
因为拥有两种方式,可以灵活在字符串中包含引号和撇号。
'I told my friend, "Python is my favorite language!"' "The language 'Python' is named after Monty Python, not the snake." "One of Python's strengths is its diverse and supportive community."
1.title()首字符大写
>>> name = "liu bin" >>> print (name.title()) Liu Bin
2.upper()全部大写转换
>>> name = "liu bin" >>> print (name.upper()) LIU BIN
3.lower()全部小写转换
>>> name = "Liu Bin" >>> print (name.lower()) liu bin
简单的"+"加号既可以实现啦。
>>> first_name = "Bin" >>> last_name = "Liu" >>> full_name = last_name + " " + first_name >>> print (full_name) Liu Bin
制表符:\t
>>> print ("python") python >>> print ("\tpython") python
换行符:\n
>>> print ("pythonPHP") pythonPHP >>> print ("python\nPHP") python PHP
整数加减乘除
>>> 2 + 3 5 >>> 3 - 2 1 >>> 2 * 3 6 >>> 3 / 2 1.5
乘方运算
>>> 3 ** 2 9 >>> 3 ** 3 27 >>> 10 ** 6 1000000
支持括号优先
>>> 2 + 3*4 14 >>> (2 + 3) * 4 20
浮点运算
>>> 0.1 + 0.1 0.2 >>> 0.2 + 0.2 0.4 >>> 2 * 0.1 0.2 >>> 2 * 0.2 0.4
浮点运算结果包含的小数位可能是不确定的,所有语言都会存在这种问题,不用担心,后面有解决方法的
>>> 0.2 + 0.1 0.30000000000000004 >>> 3 * 0.1 0.30000000000000004
str()
错误的例子:
>>> age = 23 >>> message = "Happy" + age +"rd Birthday!" Traceback (most recent call last): File "<pyshell#79>", line 1, in <module> message = "Happy" + age +"rd Birthday!" TypeError: must be str, not int
所以用str()转换
>>> message = "Happy " + str(age) + "rd Birthday!" >>> print (message) Happy 23rd Birthday!
Python中使用#注释,换行注释可以使用三引号
# 向大家问好 print("Hello Python people!")
2-1
message = "Code Geass" print(message)
2-2
message = "Code Geass" print(message) message = "Psycho-Pass" print(message)
2-3
name = "Victorique" print("Hello, " + name + "!")
2-4
name = "Victorique" print(name.lower()) print(name.upper()) print(name.title())
2-5
print('Lelouch said, "Yes, your mejesty."')
2-6
famous_person = "Lelouch" message = famous_person + ' said, "Yes, your mejesty."' print(message)
2-7
name = "\tLelouch\n" print(name.lstrip()) print(name.rstrip()) print(name.strip())
2-8
print(5 + 3) print(10 - 2) print(2 * 4) print(int(16 / 2))
2-9
num = 6 message = "My favorite nummber is " + str(num) + "." print(message)
以上就是本次给大家分享的全部知识点内容总结,大家还可以在下方相关文章里找到儿童python编程入门书籍推、 spring+springmvc+mybatis整合注、 vue项目中使用md5加密以及、 等python文章进一步学习,感谢大家的阅读和支持。
展开 +
收起 -
Copyright 2018-2019 xz577.com 码农之家