Вы находитесь на странице: 1из 2



Chapter 1:

print "Welcome to Python!"

Variables: A variable stores a piece of data and gives it specific name.

For Example:

Spam = 5

The variable spam now stores number 5.

Booleans: A Boolean is like a light switch. It can have only two values. Like light switch can only be
on or off. A Boolean can only be true or false.

We can store Booleans like

a = true

b = false

Interpreter: The interpreter runs your code line by line, and checks for any errors.

Single Line Comments: The # sign is for comments. A comment is a line of text that Python won't try
to run as code. It's just for humans to read.

Exponentiation: for exponentiation in python we use ** instead of *.

Modulo: Modulo returns the remainder from a division. So, if you type 3 % 2, it will return 1,
because 2 goes into 3 evenly once, with 1 left over.

Bringing It All Together

Nice work! So far, you've learned about:

 Variables, which store values for later use

 Data types, such as numbers and booleans
 Whitespace, which separates statements
 Comments, which make your code easier to read
 Arithmetic operations, including +, -, *, /, **, and %
Access by Index
Great work!
Each character in a string is assigned a number. This number is called the index. Check
out the diagram in the editor.
c = "cats"[0] n = "Ryan"[3]
1. In the above example, we create a new variable called c and set it to "c", the character at
index zero of the string "cats".
2. Next, we create a new variable called n and set it to "n", the character at index three of the
string "Ryan".

In Python, we start counting the index from zero instead of one.

Length of String:

len() prints the length of string.

You can use the lower ( ) method to get rid of all the capitalization in your strings.

Now let's look at str(), which is a little less straightforward. The str() method turns
non-strings into strings!

Dot Notation
Let's take a closer look at why you use len(string) and str(object), but dot notation
(such as "String".upper()) for the rest.