Reference
Zed Shaw-learn Python the Hard
Ex0:the Setup
Windows
Python 2, Atom, Terminal.
EX1:A Good First Program
Keyword
1 Print 2 Print " "
Run the file
1 python ex1.py
Error
Garbled Chinese
Possible Solutions (unfortunately, none of them works.)
1. Add ASCII Encodings
1 # -*-coding:utf-8-*-
2. Decode & ENCODE01
1 Print ' English '. Decode ("utf-8"). Encode ("gb2312") 2 Print ' English '. Decode ("utf-8"). Encode ("gbk")
3. CHCP COMMAND01, 02
1 chcp 65001
01 about the Python output in the win terminal Chinese garbled problem
Windows Setup cmd command line encoding
Ex2:comments and Pound characters
Keywork
1 # 2 # Comments
Q: If # is for comments and then how come # -*-coding: utf-8 -*- works?
A: Python still ignores as code, but it's used as a kind of "hack" or workaround for problems with setting and detecting The format of a file. You also find a similar kind of the comment for editor settings.
Q: Why does the # in print "Hi # there." not get ignored?
A: The # in that code was inside a string, so it would be put-into the string until the ending "character was hit. These pound characters is just considered characters and aren ' t considered comments.
Ex3:numbers and Math
Keywords
1+#Plus2-#minus3/#Slash:7/4 = 1; 7.0/4.0 = 1.754*#Asterisk5%#percent; modulus:x divided by Y with J-remaining, the result of is the J part.6<#Less-than7>#Greater-than8<=#less-than-equal9>=#greater-than-equal
Ex4:variables and Names
Ex5:more Variables and Printing
Keywords
1 ' Black ' 2 ' Black ' 3 Print " She ' s got%s eyes and%s hair. " % (My_eyes, My_hair)
Operations String Formatting
Differences between%r and%s in Python
Learn Python the hard