笨办法学python3 pdf百度云,笨办法学python3进阶篇

本篇文章给大家谈谈learn python the hard way (笨办法学python),以及“笨办法”学python(第3版),希望对各位有所帮助,不要忘了收藏本站喔。

Notes of Learn Python 3 the Hard Way

Learn Python 3 the Hard Way 是面对Python初学者的基础书籍,Python奠基无出其右。
这篇笔记会做到到总结所得,列出疑问,以及制作复习题用python画笑脸代码

ex1.py print()

English:

print("I'd much rather you 'not'.") 
  • would rather 用法 主要用来表示“宁愿;宁可”,它有两种用法:不带从句和带从句。
  • ^: Caret [ˈkærit]
  • #: An “octothorpe” [ˈäktəˌTHôrp] is also called a “pound”, “hash”, “mesh”.

Python: Additional Questions

  1. Make your print another line.
  2. Make your print only one of the lines.
print("Hello Wold!\n")
print("Hello Again",end=" ")
print("I like typing this")

Hello Wold!
(space)
Hello Again I like typing this

  • 在做加分题的过程中,发现print() 还有  \n   \r  ,end ="_"  等用法。
    (这么有内涵呢?!需要制作练习题)

ex2.py #的用法

Python:

  • backward reading = checking & debug (反着读代码,有利于纠错。)

ex3.py + - * /

English:

  • /: slash
  • *: asterisk

Python:

print(4%2)
print(100%13)

0
9

  • %: % means X divided by Y with J remaining(能否被整除?除后是否有剩余值?).
  • 运算顺序:运算顺序是从左到右一步进行乘法和除法(M&D),然后从左到右一步加法和减法.
    这个规则是PEMDAS,为指数乘除法减法的英文的缩写(Parentheses Exponents Multiplication Division Addition Subtraction).
  • PEMDAS有什么用?会犯什么错?

ex4.py

Good variables = good name = stop lost

=: = is called (equals) and that its purpose is to give data (numbers, strings, etc.) names (cars_driven, passengers).
==: The == (double-equal) tests whether two things have the same value.

  • 什么时候用int or floating?

ex5.py

ex6.py .format

#预留空位,用.format写入variable
hilarious = True #boolean values
joke_evaluation = "Isn't that joke so funny?! {}"

print(joke_evaluation.format(hilarious))

There are 10 types of people.
Those who know binary and those who don’t.
I said: There are 10 types of people.
I also said: ‘Those who know binary and those who don’t.’
Isn’t that joke so funny?! True

  • 归纳进print 用法:string里有{},后接.format
w = "This is the left side of ..."
e = "a string wit ha right side."

print (w + e)

This is the left side of …a string wit ha right side.

  • Explain why adding the two strings w and e with + makes a longer string. 卧槽?哲学问题?

ex7.py

print ("." * 10) # What'd that do? Repeat 10 times
  • 归纳进print 用法

ex8.py

formatter = "{} {} {} {}"
print (formatter.format(formatter,formatter,formatter,formatter))

答案是?

ex9.py

ex10.py

English: keep you on your toes. 保持警惕
Python: escape sequences = encodes difficult-to-type characters into a string.

  • 整理 all listed escape sequences

ex11.py

English: Now it is time to pick up the pace. 现在要加快脚步了。
Python:

print ("How old are you?", end = ' ') #end's default value is 'Enter'
x = int(input()) #input with int data

ex12.py

English:

  • Now it is time to pick up the pace. 现在要加快脚步了。
  • (): parenthesis characters.

Python:

print("How old are you?", input()) #input() run first,then string. #why input() could run?

阅读帮助文件的命令: (python -m pydoc {}).format (open, file, os or sys.)

ex12.py

Python:

from sys import argv #add features (modules)

, first, second, third, hahaha = argv 
#Argument variable holds arugments
#is  a default variable? all strings, convert them if need

print("The  is called:", )
print("The 1st variable is:", first)
print("Your 2nd variable is:", second)
print("Yr 3rd variable is:", third)
print("Yr test variable is:", hahaha)

argv的第一个值默认是, argv要从terminal启动

"""
f:
cd LIBARARY\PYTHON\
cd '.\Python Books\Learn Python3 the Hard Way\'
    by using: cd P "Tab"...
"""

How to access to a folder through Terminal.

ex14.py argv input format的练习

from sys import argv

, user_name = argv
prompt = '> '

print (f"Hi {user_name}, I'm the {} .")
print ("I'd like to ask you a few questions.")
print (f"Do you like me {user_name}?")
likes = input (prompt)

print (f"Where do yo u live {user_name}?")
lives = input (prompt)

print ("What kind of computer do you have?")
computer = input (prompt)

print (f"""
Alright, so you said {likes} about likeing me. 
You live in {lives}. Not sure where that is.
And you have a {computer} computer. Nice.
""") #.One way to use format 
  • 貌似最好的复习方法就是重新打一遍代码。。。?怎么整体的整理归纳呢?

ex15.py read a file

.open(), .read(), input(), close()

from sys import argv 

, filename = argv

txt = open(filename)

print (f"Here's your file {filename}:")
print (txt.read()) #。我们在 txt 上调用了一个函数。 ???raw_input???
txt.close()
print ("Type the filename again:")
file_again = input ("> ")

txt_again = open(file_again) #open 1st, read 2nd

#print (txt_again.read())
txt_again.close()

#python -m pydoc open
#r,w,x,a modes
  • 提炼重点

ex16.py

close(),read(),readline(),truncate(),write(),seek()

, filename = argv

print (f"We're going to erase {filename}.")
print ("If you don't want that, hit CTRL-C (^C).")
print ("If you do want that, hit RETURN.")

input ("?")

print ("Opening the file...")
target = open (filename, 'w')

print ("Truncating the file. Goodbye!")
target.truncate()

line1 = input ("line 1: ")
line2 = input ("line 2: ")
line3 = input ("line 3: ")

print ("I'm goting to write these to the file.")

target.write (f"{line1}\n{line2}\n{line3}\n")

print ("And finally, we close it.")
target.close()
  • 提炼重点
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值