Introduction to Python

Ace your homework & exams now with Quizwiz!

Modulo

% (the remainder)

Python

A programming language

Access by index

Allows you to find the nth index of "text" by "text"[n-1]

variable

Allows you to store data in the program

not, and, or

Boolean operators, order of operations:

String

Can contain letters, numbers, and symbols

Interpreter

Checks for errors

IDE

Integrated DeveLopment Environment

Python was named after

Monty Python's Flying Circus

boolean comparators

Name the following: == != < <= > >=

print "%d squared is %d." % (n, squared)

Print "var squared is var" using signed integer decimal format.

print("%.2f" % total)

Print total to two decimals

print

Prints anything after this command to the screen

comma

Separates variables and strings in print statement

single line Comments

Starts with #

*.py

The Python file extension

%, %s

The ___ operator will replace a ___ in the string with the string variable that comes after it.

IndentationError: expected an indented block

The error message you receive when the whitespace is off

4 spaces

The proper number of spaces when indenting your Python code

'alpha' "bravo" str(3)

Three ways to create strings

Multi line comments

Triple '''

boolean are either....

True or false

"""..."""

Used for multi-line commenting in Python

#...

Used for single line commenting in Python

IDLE

What Python calls their "Integrated DeveLopment Environment"

Run (or F5)

Will execute your program so you can test it works

function

a block of organized, reusable code that is used to perform a single, related action

if / then statement

a conditional answered with boolean

parameter

a variable name for a passed in argument

quotes

are used to go around a string

from datetime import datetime now = datetime.now()

assigning the current date and time to a variable called 'now'

=

assigns a value to a variable

\\

backslash escape sequence to show actual backslash

\b

backspace

\r

carriage return

Area where you write your code

code editor

.lower()

converts string to lowercase

.upper()

converts string to uppercase

from datetime import datetime

datetime library

def

defining a function

len()

determines the length

\"

double quote with the backslash escape sequence

eggs = 10 ** 2

eggs = 100

==

equal to

/

evaluate as a float (with decimal)

(10 + 17) == 3**16

evaluates to be FALSE

(20 - 10) > 15

evaluates to be FALSE

-22 >= -18

evaluates to be FALSE

1**2 <= -1

evaluates to be FALSE

4**2 != 16

evaluates to be FALSE

99 != (98 + 1)

evaluates to be FALSE

True and false is ____.

evaluates to be FALSE

100 == (2 * 50)

evaluates to be TRUE

19 <= 19

evaluates to be TRUE

20 != 10*2

evaluates to be TRUE

3**2 <= 9

evaluates to be TRUE

40 * 4 >= -4

evaluates to be TRUE

5*12 >= 6

evaluates to be TRUE

True or False is ____.

evaluates to be TRUE

shortened code: value+=2

expanded code: value = value+2

print "I have " +str(2) + " coconuts!"

explicit string conversion

**

exponents

Control flow

gives us this ability to choose among outcomes based off what else is happening in the program.

>

greater than

>=

greater than or equal to

\

initiate escape sequence

name = input("What is your name?")

input syntax

<

less than

<=

less than or equal to

string

letters or characters that are printed in the program

-

minus

*

multiply

Set the variable my_bool to the value True

my_bool = True

Set the variable my_float to the value 1.23

my_float = 1.23

Set the variable my_variable equal to the value 10

my_variable = 10

\n

new line

!=

not equal to

Data types

numbers and booleans

code segment: ss = "Sammy Shark!" print(ss[4])

output: y

+

plus

from datetime import datetime now = datetime.now() print '%s:%s' %(now.hour, now.minute)

print the time

or

returns TRUE when at least one expression on either side is TRUE

and

returns TRUE when expressions on both sides are TRUE

abs()

returns the absolute value

max()

returns the largest argument

modulo

returns the remainder from a division

min()

returns the smallest argument

interpreter

runs your code line by line, and checks for any errors

\'

single quote with the backslash escape sequence

%s

string placeholder

'%s' % (str)

string substitution

\t

tab

len(), upper(), lower()

three other string methods

str()

turn non-strings into strings

from * import *

universal function import

whitespace

used in Python to structure the code

integer

used in calculations - a whole number - does NOT have quotes around them

year, day, month, time

what does datetime.now() print?

reassigning

when you change the value of a variable

4 // 5

will evaluate as an int


Related study sets

CCNA 3 v7 Modules 6 - 8: WAN Concepts Exam

View Set

Another word for an educated guess in Science

View Set

Charles Rennie Mackintosh: Scottish Art Nouveau

View Set