0% found this document useful (0 votes)
15 views

Python Basics

Python module 1 notes

Uploaded by

Johnny GAMER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Python Basics

Python module 1 notes

Uploaded by

Johnny GAMER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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