9 月 152020
 
first = "任何在双引号之间的字符,"
second = '或者任何在单引号之间的字符,都是字符串。'
third = '''三引号之间的内容,可以在
完成所有内容之前换行。'''
#字符串基本用法
#字符串作为值赋予变量
what_he_does = ' plays'
his_instrument = ' guitar'
his_name = 'Robert Johnson'
artist_intro = his_name + what_he_does + his_instrument
#打印变量
print(artist_intro)
print(first + second + third)
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
Robert Johnson plays guitar
任何在双引号之间的字符,或者任何在单引号之间的字符,都是字符串。三引号之间的内容,可以在
完成所有内容之前换行。
PS C:\Users\harveymei>
9 月 152020
 
# -*- coding:utf-8 -*-
#指定字符集
file = open('C:/Users/harveymei/Desktop/newfile.txt','w')
file.write('将内容写入文件')
#在Windows的文件系统路径中,应当使用/斜线而不是\斜线
#打开一个文件,如果不存在就创建,对文件执行写入
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
PS C:\Users\harveymei> cat C:/Users/harveymei/Desktop/newfile.txt
将内容写入文件
PS C:\Users\harveymei>
9 月 152020
 
a = 100
A = 200
print(a)
print(A)
#对变量赋值同时打印变量值
#python语言对大小写敏感,因此变量a和A时两个不同的变量
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
100
200
PS C:\Users\harveymei>
9 月 152020
 
# -*- coding: utf-8 -*-
print ("Hello World!")
print ("hello Again!")
print ("这是python3的print函数")
print ("与python2的不同之处在于需要在字符串之外增加括号")
# 使用#号来注释
# 使用UTF-8编码避免乱码
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
Hello World!
hello Again!
这是python3的print函数
与python2的不同之处在于需要在字符串之外增加括号
PS C:\Users\harveymei>