Python Crash Course: A Hands-On, Project-Based Introduction to Programming
Rate it:
7%
Flag icon
You can change the value of a variable in your program
7%
Flag icon
at any time, and Python will always keep track of its current value.
7%
Flag icon
Variable names can contain only letters, numbers, and underscores. They can start with a letter or an underscore, but not with a number.
7%
Flag icon
Spaces are not allowed in variable names, but underscores can be used to separate words in variable names.
7%
Flag icon
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.
7%
Flag icon
Variable names should be short but descriptive.
7%
Flag icon
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.
7%
Flag icon
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.
8%
Flag icon
A method is an action that Python can perform on a piece of data.
8%
Flag icon
Every method is followed by a set of parentheses, because methods often need additional information to do their work.
8%
Flag icon
The title() function doesn’t need any additional information, so its parentheses are empty.
8%
Flag icon
title() displays each word in titlecase, where each word begins w...
This highlight has been truncated due to consecutive passage length restrictions.
8%
Flag icon
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
8%
Flag icon
Python uses the plus symbol (+) to combine strings.
8%
Flag icon
You can use concatenation to compose a message and then store the entire message in a variable:
8%
Flag icon
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.
8%
Flag icon
To add a tab to your text, use the character combination \t as shown
8%
Flag icon
To add a newline in a string, use the character combination \n:
8%
Flag icon
print("Languages:\n\tPython\n\tC\n\tJavaScript") Languages:     Python     C     JavaScript
8%
Flag icon
It’s important to think about whitespace, because often you’ll want to compare two strings to determine whether they are the same.
8%
Flag icon
Fortunately, Python makes it easy to eliminate extraneous whitespace from data that people enter.
8%
Flag icon
Python can look for extra whitespace on the right and left sides of a string.
8%
Flag icon
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.
8%
Flag icon
To remove the whitespace from the string permanently, you have to store the stripped value back into the variable:
8%
Flag icon
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():
8%
Flag icon
In the real world, these stripping functions are used most often to clean up user input before it’s stored in a program.
8%
Flag icon
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.
9%
Flag icon
Python uses two multiplication symbols to represent exponents:
9%
Flag icon
use parentheses to modify the order of
9%
Flag icon
Python calls any number with a decimal point a float.
9%
Flag icon
But be aware that you can sometimes
9%
Flag icon
get an arbitrary number of decimal places in your answer: