Python Basics

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

In python 2+2 is called an expression.

Expressions consist of
values(such as 2) and operators(such as +), and they can always
evaluate down to a single value
THE LEN() FUNCTION
print('The length of your name is:’)
print(len(myName))
Enter the following into the interactive shell to try this:
>>> len('hello’)
5
>>> len('My very energetic monster just scarfed nachos.’)
46
>>> len(‘’)
0

The str(), int(), and float()


Functions
>>> str(29)
'29’
>>> int('42’)
42
>>> int('-99’)
-99
>>> float('3.14')
3.14
>>> float(10)
10.0
DISSECTING YOUR PROGRAM
Comments
The following line is called a comment.
# This program says hello and asks for my name.

The print() Function


The print() function displays the string value inside the parentheses on the screen.
print('Hello world!’)
print('What is your name?') # ask for their name

The input() Function


The input() function waits for the user to type some text on the keyboard and press ENTER.
myName = input()

Printing the User’s Name


print('It is good to meet you, ' + myName)

You might also like