Section 1

Preview this deck

elif statement

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (132)

Section 1

(50 cards)

elif statement

Front

This statement can be used when you want one of many possible clauses to run. It consists of the elif keyword, a condition, a colon, and an indented block of code. Ex. if condition: .......... elif name == 'Bob': print('Hi Bob') else: .......... Note: once one of these conditions is found to be True all others are skipped. If the if and elif statements are False only the else statement will run.

Back

try and except

Front

These keywords allow you to handle errors. Ex. try: some code that might work. except error_name_here: error message that you wrote.

Back

round()

Front

This function is used to round floats. Ex. round(3.14) 3 round(1.5) 2

Back

break

Front

This keyword is used to break out of a loop when it is approached by the program.

Back

else statement

Front

This flow control statement only runs when the if statement or elif statements are false. It uses the else keyword, a colon, and then an indented block of code. Ex. else: print('You're not Alice')

Back

Condition

Front

An expression that evaluates down to a Boolean value.

Back

Data Type

Front

A category into which values fall into. This can include strings, integers, or floats. Ex. int: 5, -3, 1 float: 3.14, -1.5, 4.0 string: 'Hello World', '101 Dalmatians' note: Strings must be within either single quotes or double quotes.

Back

Initialization

Front

The first time a variable is created or the first time a value is stored in a variable.

Back

None

Front

A data type in Python consisting only of the keyword None. This represents the absence of a value. It is helpful when you need to store something that won't be confused for a real value in a variable. Note: As with True and False, None must be capitalized.

Back

random.randint()

Front

This function is used to generate random numbers. It can be passed two arguments. Ex. random.randint(0, 10) This code will generate any random number between 0 and 10. Note: You must import the random module to use this function.

Back

abs()

Front

This function returns the absolute value of the number passed to it. Ex. abs(-5) 5 abs(3.14) 3.14

Back

overwriting

Front

When a variable is assigned a new value the old one is forgotten.

Back

return statement

Front

Used to declare what a function returns when it evaluates an expression. To write a return statement you use the return keyword and the value or expression that the function should return. Ex. return 2 + 2

Back

str()

Front

This function is used to convert an integer or a float into a string. Ex. str(29) '29'

Back

Comment

Front

A line that Python ignores. These are used to document your code and make it easier for you and others to understand the code when looked at later. To create a comment: # This is a comment in Python

Back

Operator

Front

A symbol that performs an operation on some values. Ex. +, -, , /, %, *

Back

Expression

Front

The most basic kind of programming instruction. Consists of values and operators that can reduce down. Ex. 2 + 2

Back

input()

Front

Waits for the user to type some text on the keyboard and press enter. This input can be saved to a variable like so: spam = input() Note: The value stored using the input function is a string value.

Back

What are legal variable name?

Front

It can only be one word. It can only use letters, numbers, and the underscore character. It can't begin with a number. Note: variable names are case-sensitive meaning Spam and spam are considered different variables.

Back

Boolean Values

Front

The values True or False are Boolean values. They are keywords and cannot be used as variables. You must capitalize the first letter of either of these keywords. Ex. spam = True

Back

continue

Front

This keyword jumps to the beginning of the loop when it is encountered.

Back

global scope

Front

Every part of the program has access to variables in the global scope. Note: Global variables can be read from local scope.

Back

variable

Front

A place in the computer's memory where you can store a single value. The example below shows how to declare a variable. You can use variables in expressions with other variables. Ex. spam = 42

Back

import

Front

This keyword is used to import a module into your program. A module is a Python program that contains a group of related functions that can be used in your program. An import statement consists of: Ex. import random or from random import * Note: an import statement can include more than one module. Ex. import sys, os, math, random

Back

while loop

Front

A control structure that makes an area of code run multiple times. It will run while a condition is True. It consists of the while keyword, a condition, a colon, and an indented block of code. Ex. spam = 0 while spam < 5: print('Hello') spam = spam + 1 This code prints Hello five times. Note: If you are trapped in an infinite loop in the shell you can press ctrl + c to escape it.

Back

Comparison Operators

Front

These operators compare two values and reduce down to a single Boolean value, either True or False == Equal to: Can work with any data type != Not equal to: Can work with any data type < Less than > Greater than <= Less than or equal to >= Greater than or equal to

Back

int()

Front

This function converts string values or floats into integers. Ex. int('29') 29 int(3.14) 3 Note: The int function can be used to round floats down or up. To round up just add 1 after passing the argument to the int function. Note: If you pass a value to int that cannot be evaluated as an integer Python will give you a ValueErrror. Ex. int('99.99') ValueError: invalid literal for int() with base 10: '99.99'

Back

+

Front

When put between two numerical values it becomes the addition operator. When put between two strings it becomes the concatenation operator. Ex. 2 + 2 4 'Hello ' + 'World' 'Hello World' Note: Python will not understand the expression if you try to add an integer value and a string. Ex. 'Alice' + 42 TypeError: Can't convert 'int' object to str implicitly.

Back

global

Front

This is a keyword in Python that allows you to define a global variable within a functions code block.

Back

float()

Front

This function converts integers into floats. Ex. float(4) 4.0

Back

Code Block

Front

Where a group of code begins and ends. In Python code begins with an indentation and ends when the indentation decreases to zero. Note: blocks can contain other blocks.

Back

=

Front

This is the assignment operator it assigns a value to a variable

Back

Text and Number Equivalence

Front

If an integer and a float are the same number they are considered equal. Ex. 42 == 42.0 True But an integer and a string or a float and a string are not considered equal. Ex. 42 == '42' False 42.0 == '42' False

Back

Argument

Front

A value that is passed to a function.

Back

print()

Front

This function displays the text data within it to the screen. Ex. print('Hello World') Hello World

Back

argument

Front

A value that is passed to a function

Back

local scope

Front

The programs access to variables within a code block. Local scope refers to variables that reside in code blocks. Note: When a scope is destroyed all values within it are forgotten. Note: Local variables cannot be used in the global scope.

Back

for loop

Front

This loop runs code a set amount of times. It consists of the for keyword, a condition, a colon, and an indented block of code. Ex. for

Back

function

Front

A function is like a mini program within a program. It allows programmers to group code. They also prevent you from having to repeat code.

Back

Order of operations/ precedence

Front

A mathematical rule stating that mathematical operations in a formula are calculated in this order (1) exponents and roots, (2) multiplication and division, and (3) addition and subtraction. You can use parentheses to overwrite the normal order of operations.

Back

parameter

Front

A variable that an argument is stored in when a function is called. Note: The value stored in a parameter is forgotten when the function returns.

Back

Boolean Operators

Front

The Boolean operators are and, or, and not. They are used to compare Boolean values and like comparison operators they evaluate down to Boolean values. Ex. True and True True True and False False

Back

len()

Front

Takes a string value and returns the length of the value as an integer.

Back

def

Front

This is the keyword in Python used to define a function. Ex. def some_function(): some code in this block Note: Defining a function does not call it. To call the function you type function_name()

Back

SyntaxError: EOL While scanning string literal

Front

This error happens when you forget to add the closing quote to a string or the closing parentheses to a function when calling it.

Back

range()

Front

This function allows you to give it an integer value that can be used with a for loop to run through a sequence of integer values. Note: range() can be passed multiple values. Ex. range(12, 16) This will start at 12 and will go up to but not include 16. Ex. range(12, 16, 2) This will start at 12 and will go up to but not include 16 in increments of 2.

Back

if statement

Front

This is a flow control statement: begins with the keyword if, next a condition, a colon, and starting on the next line an indented block of code(the clause). Ex. if name == 'Alice': print('Hi, Alice')

Back

*

Front

When put between two numerical values it becomes the multiplication operator. When used between a string and an integer it will replicate that string that number of times. Ex. 'String' * 3 'StringStringString' Note: If Python gets anything other than these two conditions it will give you an error. 'String' * 4.5 TypeError: can't multiply sequence by non-int of type 'float'

Back

sys.exit()

Front

This function can be used to terminate a program. Note: The sys module must be imported to use this function.

Back

Flow Control

Front

Decides which statements in a program should run.

Back

Section 2

(50 cards)

in

Front

This keyword determines if an item is in a list. It will return a Boolean value. Ex. 'hello' in ['greetings', 'salutations', 'hello'] True

Back

not in

Front

This keyword determines if an item is not in a list. It will return a Boolean value. Ex. 'goodbye' not in ['greetings', 'salutations', 'hello'] True

Back

del

Front

This keyword can be used to remove a value from a list. Ex. spam = ['cat', 'bat', 'rat'] del spam[1] ['cat', 'rat']

Back

insert()

Front

This method adds a value to a list. It adds this value to the index you specify. It takes two arguments, the index and the value to be added. Ex. spam.insert(2, 'spider') ['cat', 'rat', 'spider', 'bat']

Back

islower()

Front

Returns a Boolean value True if the string has at least one letter and all the letters are lowercase.

Back

isspace()

Front

Returns True if the string consists only of spaces, tabs, and new-lines and is not blank.

Back

isalnum()

Front

Returns True if the string consists only of letters and numbers and is not blank.

Back

istitle()

Front

Returns True if the string consists only of words that begin with an uppercase letter followed by only lowercase letters.

Back

startswith()

Front

Returns True if the string value it is called on begins with the string passed to it.

Back

center()

Front

Returns a padded version of the string it is called on. It centers the string.

Back

sort()

Front

This method is used to sort items in a list. The items can be sorted alphabetically or numerically. If reverse=True is passed to this method it will return the sorted list reversed. Note: You cannot sort lists with both strings and numbers in them. Note: Pass key=str.lower to make sure the list is in order.

Back

List

Front

A value that contains multiple values in a sequence. A list begins and ends with square brackets. Ex. ['this', 'is', 'a', 'list']. Note: methods and functions that work with strings can generally be used with lists.

Back

rstrip()

Front

Strips the white space in a string off of the right side.

Back

Item

Front

A value inside of a list.

Back

get()

Front

When used with dictionaries this method takes two arguments. The key of the value to be accessed and the value to return if said key doesn't exist in the dictionary.

Back

lstrip()

Front

Strips the white space in a string off of the left side.

Back

values()

Front

This method can be used to access values in a dictionary.

Back

isalpha()

Front

Returns True if the string consists only of letters and is not blank.

Back

lower()

Front

Changes all the letters in a string to be lowercase.

Back

items()

Front

This method can be used to access whole key value pairs in a dictionary.

Back

Index

Front

The integer inside the brackets that follow a list. An index is used to access specific values within a list. Ex. spam[1] 'bat' Note: Python will give you an error if you use an index that is not in the range of the available indexes. Note: Indexes can only be integer values.

Back

Multiline Strings

Front

A string that can span multiple lines in Python. The create a multiline string you put text between ''' text here '''.

Back

split()

Front

This method splits a string into a list of strings at the point you pass as an argument. The default is a space.

Back

append()

Front

This method adds a value to a list. It adds this value to the end of the list. Ex. spam.append('bat') ['cat', 'rat', 'bat']

Back

join()

Front

This method combines a list of string values into a single string value. Ex. ', '.join('cats', 'rats', 'bats') 'cats, rats, bats'

Back

dictionary

Front

A collection of many values. It stores data in key value pairs as opposed to indexes. Ex. cat = {'color': 'gray','disposition': 'loud'} Note: Unlike lists items in dictionaries are unordered

Back

index()

Front

This method allows you the find the index of the list value you pass it. Ex. spam.index('hello') 1

Back

Escape character

Front

These are used so that Python doesn't confuse a ' or " for the ending quote in a string. The \ is the escape character in Python. Ex. 'That is Alice\'s cat.' \' Single quote \" Double quote \t Tab
Newline (line break) \\ Backslash

Back

Multiline Comments

Front

A comment that can span multiple lines in Python. To create a multiline comment put your information between """ text here """.

Back

list()

Front

This function converts tuples and strings to lists.

Back

upper()

Front

Changes all the letters in a string to be uppercase.

Back

ljust()

Front

Returns a padded version of the string it is called on. It justifies the string to the left.

Back

Raw String

Front

A string that completely ignores all escape characters and prints any backslash that appears in the string. Ex. print(r'That is Carol\'s cat.') That is Carol\'s cat.

Back

copy

Front

This function is used to copy a list. Note: In order to use this function you must import the copy module.

Back

pprint()

Front

This function can be used to "pretty print" a dictionary. Ex. pprint.pprint(count) Note: You must import the pprint module to use this function.

Back

rjust()

Front

Returns a padded version of the string it is called on. It justifies the string to the right.

Back

tuple()

Front

This function converts lists and strings to tuples.

Back

endswith()

Front

Returns True if the string values it is called on ends with the string passed to it.

Back

method

Front

A method is the same thing as a function except it is called on a value. Ex. spam.index('hello')

Back

Slice

Front

Used to get several specific values in the form of a new list. Ex. spam[1:4] This will get the values at indexes one up to but not including four.

Back

keys()

Front

This method can be used to access keys in a dictionary.

Back

Tuple

Front

Is similar to a list except in that the values it contains are immutable and cannot be changed or appended. Note: Strings are also immutable.

Back

reference

Front

A value that points to some bit of data.

Back

type()

Front

This function displays the data type of the value that is passed to it.

Back

pformat()

Front

This function is used to pretty print a dictionary as a string.

Back

deepcopy

Front

This function is used to copy a list within a list. Note: In order to use this function you must import the copy module.

Back

isupper()

Front

Returns a Boolean value True if the string has at least one letter and all the letters are uppercase.

Back

isdecimal()

Front

Returns True if the string consists only of numeric characters and is not blank.

Back

strip()

Front

Strips the white space in a string off of both sides.

Back

remove()

Front

This method removes the list value that is passed to it. Ex. spam.remove('bat') spam ['cat', 'rat', 'elephant', 'tiger', 'snake', 'spider', 'fly', 'monkey']

Back

Section 3

(32 cards)

search()

Front

This method uses a regex pattern to search for text in a string that it is called on. Ex. phone_regex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d') mo = phone_regex.search('A string with 415-555-9999.')

Back

Absolute path

Front

A path which always begins with the root folder.

Back

os.path.exists(path)

Front

Returns True if the file or folder referred to in the argument exists and will return False if it does not exist. Note: can be used to determine if a DVD or flash drive is currently attached to the computer.

Back

extension

Front

The part of the filename after the last period. Tell you what the file's type is.

Back

os.path.isdir(path)

Front

Returns True if the path argument exists and is a folder and will return False otherwise.

Back

Relative path

Front

A path which is relative to the program's current working directory.

Back

os.path.abspath(path)

Front

This function will return the string of the absolute path of the argument. Ex. os.path.abspath('.') 'C:\\Python34'

Back

character class(shorthand)

Front

\d = any numeric digit between 0 and 9. \D = anything that is not a numeric digit between 0 and 9. \w = any letter, numeric digit, or underscore character. \W = any character that is not a numeric digit, letter, or underscore character. \s = any space, tab, or newline character. \S = any character that is not a space, tab, or newline character.

Back

re

Front

This module allows the use of regular expressions when imported into a program. Ex. import re

Back

os.path.getsize(path)

Front

This function returns the size in bytes of the file in the path argument. Ex. os.path.getsize('C:\\Windows\\System32\\calc.exe') 776192

Back

os.path.relpath(path)

Front

This function will return a relative path from the start path to path. If start is not provided, the current working directory is used as the start path. Ex. os.path.relpath('C:\\Windows', 'C:\\')

Back

.close()

Front

This method is used to close a file.

Back

copy()

Front

This function copies text to the clipboard. Note: Must import pyperclip.

Back

os.path.isabs(path)

Front

This function will return True if the argument is an absolute path and False if it is a relative path. Ex. os.path.isabs('.') False

Back

.read()

Front

This method is used to read the contents of a file.

Back

paste()

Front

Receives text from the clipboard. Note: Must import pyperclip.

Back

os.path.join()

Front

This function will join the file and folder names you pass it together. Ex. import os os.path.join('usr','bin','spam') 'usr\\bin\\spam'

Back

os.path.dirname(path)

Front

This function will return a string of everything that comes before the last slash in the path argument. Ex. os.path.dirname(path) 'C:\\Windows\\System32'

Back

Folders/Directories

Front

Used to contain files and other directories.

Back

root folder

Front

The folder on a computer that contains all other folders.

Back

os.getcwd()

Front

This function gets the directory which you are in. Ex. import os os.getcwd() 'C:\\Python34'

Back

os.listdir(path)

Front

This function returns the list of filename strings for each file in the path argument. Ex. os.listdir('C:\\Windows\\System32')

Back

.open()

Front

This method is used to open a file. Note: can be given a second argument 'w' or 'a'.

Back

.write()

Front

This method is used to write contents to a file. This overwrites what was originally in the file.

Back

os.path.split(path)

Front

This function will return a tuple of the dir name and the base name together. Ex. os.path.split(calcFilePath) ('C:\\Windows\\System32', 'calc.exe')

Back

os.path.isfile(path)

Front

Returns True if the path argument exists and is a file and will return False otherwise.

Back

os.makedirs()

Front

This function is used to create new folders. Ex. import os os.makedirs('C:\\delicious\\walnut\\waffles')

Back

os.chdir()

Front

This function allows you to change the directory using the path you pass it. Ex. os.chdir('C:\\Windows\\System32') Note: Python will give you an error if you try to change to a directory that does not exist.

Back

compile()

Front

This method creates a regex pattern to be used in a program. For example the pattern of a phone number or email address. Ex. re.compile(r'\d\d\d-\d\d\d-\d\d\d\d') Note: it is easier to create these patterns using a raw string.

Back

pyperclip

Front

A module that contains functions that can send text to and receive text from your computer's clipboard.

Back

os.path.basename(path)

Front

This function will return a string of everything that comes after the last slash in the path argument. Ex. os.path.basename(path) 'calc.exe'

Back

path

Front

specifies the location of a file on a computer.

Back