More on this book
Community
Kindle Notes & Highlights
by
Eric Matthes
Started reading
May 7, 2017
You can change the value of a variable in your program
at any time, and Python will always keep track of its current value.
Variable names can contain only letters, numbers, and underscores. They can start with a letter or an underscore, but not with a number.
Spaces are not allowed in variable names, but underscores can be used to separate words in variable names.
Avoid using Python keywords and function names as variable names; that is, do not use words that Python has reserved for a particular programmatic purpose, such as the word print.
Variable names should be short but descriptive.
The Python variables you’re using at this point should be lowercase. You won’t get errors if you use uppercase letters, but it’s a good idea to avoid using them for now.
The interpreter provides a traceback when a program cannot run successfully. A traceback is a record of where the interpreter ran into trouble when trying to execute your code.
A method is an action that Python can perform on a piece of data.
Every method is followed by a set of parentheses, because methods often need additional information to do their work.
The title() function doesn’t need any additional information, so its parentheses are empty.
title() displays each word in titlecase, where each word begins w...
This highlight has been truncated due to consecutive passage length restrictions.
The lower() method is particularly useful for storing data. Many times you won’t want to trust the capitalization that your users provide, so you’ll convert strings to lowercase before storing
Python uses the plus symbol (+) to combine strings.
You can use concatenation to compose a message and then store the entire message in a variable:
In programming, whitespace refers to any nonprinting character, such as spaces, tabs, and end-of-line symbols. You can use whitespace to organize your output so it’s easier for users to read.
To add a tab to your text, use the character combination \t as shown
To add a newline in a string, use the character combination \n:
print("Languages:\n\tPython\n\tC\n\tJavaScript") Languages: Python C JavaScript
It’s important to think about whitespace, because often you’ll want to compare two strings to determine whether they are the same.
Fortunately, Python makes it easy to eliminate extraneous whitespace from data that people enter.
Python can look for extra whitespace on the right and left sides of a string.
To ensure that no whitespace exists at the right end of a string, use...
This highlight has been truncated due to consecutive passage length restrictions.
To remove the whitespace from the string permanently, you have to store the stripped value back into the variable:
You can also strip whitespace from the left side of a string using the lstrip() method or strip whitespace from both sides at once using strip():
In the real world, these stripping functions are used most often to clean up user input before it’s stored in a program.
A syntax error occurs when Python doesn’t recognize a section of your program as valid Python code. For example, if you use an apostrophe within single quotes, you’ll produce an error.
Python uses two multiplication symbols to represent exponents:
use parentheses to modify the order of
Python calls any number with a decimal point a float.
But be aware that you can sometimes
get an arbitrary number of decimal places in your answer:

