随笔分类 - Python Learning
摘要:A method is similar to a function – it takes arguments and returns a value – but the syntax is different. For example, the method upper takes a string...
阅读全文
摘要:Find: In a sense, find is the opposite of the [] operator. Instead of taking an index and extracting the corresponding character, it takes a...
阅读全文
摘要:It is tempting to use the [] operator on the left side of an assignment, with the intention of changing a character in a string. The ‘object...
阅读全文
摘要:String slicesA segment of a string is called a slice. Selecting a slice is similar selecting a character: The operator [n:m] returns the par...
阅读全文
摘要:A lot of computations involve processing a string one character at a time. Often they start at the beginning, select each character in turn, do someth...
阅读全文
摘要:len is a build-in function that returns the numbers of characters in a string: Since we started counting at zero, the last index should be 5...
阅读全文
摘要:A string is a sequence of characters. You can access the characters one at a time with the bracket operator. The second statement selects ch...
阅读全文
摘要:Loops are often used in programs that compute numerical results by starting with an approximate answer and iteratively improving it.For example, one w...
阅读全文
摘要:Computers are often used to automate repetitive tasks. Repeating identical or similar tasks without making errors is something that computers do well ...
阅读全文
摘要:Keyboard inputPython provides a build-in function called raw_input (in version 2.x) that gets input from the keyboard. In Python 3.x we use input(). W...
阅读全文
摘要:RecursionIt is legal for one function to call another; it is also legal for a function to call itself. It may not be obvious why what is a good thing,...
阅读全文
摘要:1. Modulus operator (%)The modulus operator works on integers and yields the remainder when the first operand is divided by the second. In Python, the...
阅读全文
摘要:1. Write a function called square that takes a parameter named t, which is a turtle. It should use the turtle to draw a square.from TurtleWorld import...
阅读全文
摘要:TurtleWorld provides a set of functions for drawing lines by steering turtles around the screen. You can download Swampy from allendowney.com/swampy.U...
阅读全文
摘要:It may not be clear why it is worth the trouble to divide a program into functions. There are a lot of reasons; here are few:Creating a new function gives you an opportunity to name a group of statements, which makes your program easier to read and debug.Functions can make a program smaller by elimi
阅读全文
摘要:Python is an example of high-level language. As you might infer from the name “high-level language”, there are also low-level languages, sometimes referred to as “machine languages” or “assembly languages”. Loosely speaking, computers can only execute programs written in low-level languages. So prog
阅读全文

浙公网安备 33010602011771号