Lesson
This commit is contained in:
parent
8052e5b7c0
commit
721c852f58
@ -1,4 +1,4 @@
|
||||
# Python学习基础笔记
|
||||
# Python学习笔记
|
||||
|
||||
## 一. 基本输入输出
|
||||
1. print()
|
||||
@ -7,11 +7,48 @@
|
||||
> print('hello, world')
|
||||
|
||||
print()函数也可以接受多个字符串,用逗号“,”隔开,就可以连成一串输出:
|
||||
> print('The quick brown fox', 'jumps over', 'the lazy dog')
|
||||
|
||||
```
|
||||
print('The quick brown fox', 'jumps over', 'the lazy dog')
|
||||
The quick brown fox jumps over the lazy dog
|
||||
|
||||
```
|
||||
print()会依次打印每个字符串,遇到逗号“,”会输出一个空格.
|
||||
|
||||
当需要输出双引号或单引号时可交叉使用,比如
|
||||
>print('This is my name:"Terry".')
|
||||
|
||||
当需要输出特殊字符的时候使用'\'加在前面,也可以前后加入使用'''来进行多行输出.例如:
|
||||
```
|
||||
print(''' The '\\n' means
|
||||
go to
|
||||
a new line.''')
|
||||
|
||||
>The '\n' means
|
||||
go to
|
||||
a new line.
|
||||
```
|
||||
|
||||
2. input()
|
||||
|
||||
如果要让用户从电脑输入一些字符怎么办?Python提供了一个input(),可以让用户输入字符串,并存放到一个变量里。比如输入用户的名字:
|
||||
> name = input()
|
||||
|
||||
Michael
|
||||
|
||||
但是程序运行的时候,没有任何提示信息告诉用户:“嘿,赶紧输入你的名字”,这样显得很不友好。幸好,input()可以让你显示一个字符串来提示用户,于是我们把代码改成:
|
||||
```
|
||||
name = input('please enter your name: ')
|
||||
print('hello,', name)
|
||||
```
|
||||
|
||||
## 二.基础知识
|
||||
1. 数据类型和变量
|
||||
|
||||
1.1 整数
|
||||
|
||||
1.2 浮点数
|
||||
|
||||
1.3 字符串
|
||||
|
||||
1.4
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user