Lab 1
Lab 1
Python is Interpreted: This means that it is processed at runtime by the interpreter and
you do not need to compile your program before executing it. This is similar to PERL and
PHP.
Python is Interactive: This means that you can actually sit at a Python prompt and
interact with the interpreter directly to write your programs.
Python is Object-Oriented: This means that Python supports Object-Oriented style or
technique of programming that encapsulates code within objects.
Python is Beginner's Language: Python is a great language for the beginner
programmers and supports the development of a wide range of applications from simple
text processing to WWW browsers to games.
Python is a script language: It’s a high-level programming language that
is interpreted by another program at runtime rather than compiled by the computer's
processor as other programming languages (such as C and C++).
WHY USE PYTHON INTERACTIVE
MODE
• If you want to know how something works, you can just try it. There is no
need to write up a file.
• help(anything) for documentation. It's way faster than any web interface.
• Write a program / subprogram to use once, and then never again. The
fastest way to do this is to just do it in the Python interpreter.
• When this function is called, the program stops and waits for the
user to type something.
>>> x = input()
Anything
>>> print (x)
Anything
You can pass a string to input() to be displayed to the user before
pausing for input:
>>> name = input('What is your name?\n')
What is your name?
Chuck
>>> print (name)
Chuck
v = 5 # assign 5 to v
v = 5 # velocity in meters/second.
BOOLEAN EXPRESSION
An expression that is either True or False. The following examples use the operator ==,
which compares two operands and produces True if they are equal and False otherwise:
>>> 5 = = 5
True
>>> 5 = = 6
False
True and False are special values that belong to the type bool; they are not
strings:
>>> type(True)
<type 'bool'>
x != y # x is not y
x >= y # x is greater than or equal to y
x>y # x is greater than y
x<y # x is less than an or equal to y
x <= y # x is less than or equal to y
x is y # x is the same as y
x is not y # x is not the same as y
Remember that = is an assignment
operator and == is a comparison operator. There is no such thing as =< or =>.
LOGICAL OPERATORS: AND, OR, NOT.