《编程小白的第一本python入门书》——读书笔记
笔记
a = 15
print( str(a) + '1')
//#结果为151
//#(猜测):str() 可以将int型数据转化成字符串,小数也可以这样做
def fahrenheit_converter(C):
fahrenheit = C * 9/5 + 32
return str(fahrenheit) + '。F'
C2F = fahrenheit_converter(35)
//#就是将fahrenheit_converter()函数的返回值赋值给C2F
//#调用函数好比是call,return是对call的回应,若函数中没有return,则在调用(call)的时候不会得到回应(none)
print(C2F)
(调用函数)
import 模块
模块.函数
print的sep参数可以在每个结尾设置格式
给函数设置默认参数
//#创建文件 涉及文件的写
def text_create(name,msg):
desktop_path = 'C:/Users/xyh/Desktop/new/OJ/'
full_path = desktop_path + name + '.txt'
file = open(full_path,'w')
file.write(msg)
file.close()
print("done")
text_create('hello','hello world')
def text_filter(word, censored_word = 'lame', changed_word = 'awesome'):
print(word.replace(censored_word,changed_word))
text_filter('python is lame')
//#是world.replace(旧的,新的)
True and False
python控制台(console)可以像命令行一样使用
!= 和 <>一样
当两个变量一致时,经过is对比后就会返回True
range(1,11) 实际范围是1~10