Shared Flashcard Set

Details

Python Vocabulary
All symbols and words, and their meanings
55
Computer Science
Professional
03/04/2014

Additional Computer Science Flashcards

 


 

Cards

Term
Octothorpe (#)
Definition
Using this on the beginning of a line with comment out the rest of the line
Term
Modulus (%) (in math)
Definition
Only used in division. This character represents the remainder of the division.
Term
Single Equal (=)
Definition
assigns the value on the right to a variable on the left
Term
Double Equal (==)
Definition
Tests if two things have the same value
Term
String
Definition
a series of readable or usable sentences that the user will use. Usually surrounded by double quotes (")
Term
Variable
Definition
The name of something that the code has given a value to. peanuts = 197, or x = Sally.

Variables cannot start with nubers
Term
%s
Definition
string

used to call string variables
Term
%d
Definition
digit

used to call digit variables
Term
%r
Definition
raw data or representation

used for debugging. It shows the actual code used when you run the program
Term
\n
Definition
new line character - escape sequence

if put at the end of a string it will go to the next line
Term
\\
Definition
Backslash() - escape sequence

"I am 6'2\" tall." # escape double-quote inside string
'I am 6\'2" tall.' # escape single-quote inside string
Term
"""
Definition
quotes out everything beneath/after these triple quotes until it reaches another triple quotes
Term
\'
Definition
Single-quote(')
Term
\"
Definition
Double-quote(")
Term
\a
Definition
ASCII bell (BEL)
Term
\b
Definition
ASCII backspace(BS)
Term
\f
Definition
ASCII formfeed(FF)
Term
\N(name)
Definition
Character named name in the Unicode database(Unicode only)
Term
\r ASCII
Definition
Carriage Return (CR)
Term
\t ASCII
Definition
Horizontal Tab (TAB)
Term
\uxxxx
Definition
Character with 16-bit hex value xxxx(Unicode only)
Term
\Uxxxxxxxx
Definition
Character with 32-bit hex value xxxxxxxx(Unicode only)
Term
\v
Definition
ASCII vertical tab (VT)
Term
\ooo
Definition
Character with octal value ooo
Term
\xhh
Definition
Character with hex value hh
Term
raw_input()
Definition
answer to a variable that makes the user input information

age = raw_input()
Term
int(raw_input())
Definition
allows user to input a number instead of a string

age = int(raw_input())
Term
Unicode
Definition
1:
Unicode is a way to handle textual data.
It’s not a character set, it’s not an encoding.

2:
Unicode is text, everything else is binary.
Yes, even ASCII text is binary data.

3:
Unicode uses the UCS character set.
But UCS is not Unicode.

4:
Unicode can be encoded to binary data with UTF.
But UTF is not Unicode.

http://regebro.wordpress.com/2011/03/23/unconfusing-unicode-what-is-unicode/
Term
input()
Definition
tries to convert things you enter as if they were Python code, but it has security problems.
Term
from
Definition
import module or library

How to add features to your script from the Python feature set
Term
argv
Definition
argument variable

Holds the arguments you pass to your python script when you run it.

It requires you enter in the answers to the variables when you open the program
Term
prompt
Definition
After you have a string ask a question to the user, you can use a prompt or symbols to help show the user where to enter data

prompt = '> '
likes = raw_input(prompt)
Term
open()
Definition
opens the variable listed in the parentheses

filename = raw_input()
txt = open(filename)
Term
.read()
Definition
Calls the function of 'read' on whatever is before the period

filename = raw_input()
txt = open(filename)
print txt.read()
Term
.close()
Definition
performs the function of close on whatever variable is before the '.'
Term
.readline()
Definition
performs the function of reading one line of a text file of whatever variable is before the '.'
Term
.truncate
Definition
performs the functions of emptying the file
Term
write(stuff)
Definition
performs the functions of writing stuff to the file

line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")

target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
Term
'w'
Definition
signifies this program is in write mode

target = open(filename, 'w')
Term
'r'
Definition
read mode

this is the default operation for the open() function. Allows the program to only be read and not written to
Term
sys
Definition
System library or module

This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available

http://docs.python.org/2/library/sys.html
Term
os.path
Definition
Library/module

implements useful functions on pathnames.

http://docs.python.org/2/library/os.path.html
Term
open()
Definition
Open a file, returning an object of the file type described in section File Objects. If the file cannot be opened, IOError is raised. When opening a file, it’s preferable to use open() instead of invoking the file constructor directly.

The most commonly-used values of mode are 'r' for reading, 'w' for writing (truncating the file if it already exists), and 'a' for appending (which on some Unix systems means that all writes append to the end of the file regardless of the current seek position). If mode is omitted, it defaults to 'r'.

http://docs.python.org/2/library/functions.html
Term
len()
Definition
Return the length (the number of items) of an object. The argument may be a sequence (string, tuple or list) or a mapping (dictionary)
Term
close()
Definition
Close the file. A closed file cannot be read or written any more. Any operation which requires that the file be open will raise a ValueError after the file has been closed. Calling close() more than once is allowed.

As of Python 2.5, you can avoid having to call this method explicitly if you use the with statement.
Term
with
Definition
As of Python 2.5, you can avoid having to call this method explicitly if you use the with statement. For example, the following code will automatically close f when the with block is exited:

from __future__ import with_statement

with open("hello.txt") as f:
for line in f:
print line

Note: Not all ``file-like'' types in Python support use as a context manager for the with statement. If your code is intended to work with any file-like object, you can use the closing() function in the contextlib module instead of using the object directly. See section 26.5 for details.
Term
def
Definition
defines a function

Did you start your function definition with def?
Does your function name have only characters and _ (underscore) characters?
Did you put an open parenthesis ( right after the function name?
Did you put your arguments after the parenthesis ( separated by commas?
Did you make each argument unique (meaning no duplicated names)?
Did you put a close parenthesis and a colon ): after the arguments?
Did you indent all lines of code you want in the function four spaces? No more, no less.
Did you "end" your function by going back to writing with no indent (dedenting we call it)?
Term
'use' or 'call' functions check list
Definition
Did you call/use/run this function by typing its name?

Did you put the ( character after the name to run it?

Did you put the values you want into the parenthesis separated by commas?

Did you end the function call with a ) character?
Term
*args
Definition
Tells python to take all the argyents to the function and then put them in args as a list.

similar to argv function
Term
Common amount of arguments for functions
Definition
Practical limit is around 5 arguments per function
Term
f.seek()
Definition
f.seek(o)

A file in Python is kind of like an old tape drive on a mainframe, or maybe a DVD player. It has a "read head," and you can "seek" this read head around the file to positions, then work with it there. Each time you do f.seek(0) you're moving to the start of the file.

the seek() function is dealing in bytes, not lines. So that's going to the 0 byte (first byte) in the file.
Term
f.readline()
Definition
Each time you do f.readline() you're reading a line from the file, and moving the read head to right after the \n that ends that file.
Term
+=
Definition
contraction of the operations = and +

That means x = x + y is the same as x += y
Term
readline()
Definition
How does readline() know where each line is?

There is code inside that scans each byte of the file until it finds a \n character, then stops reading the file to return what it found so far. The file f is responsible for maintaining the current position in the file after each readline() call, so that it will keep reading each line.
Term
return
Definition
The return statement is used to return from a function i.e. break out of the function. We can optionally return a value from the function as well.

Note that a return statement without a value is equivalent to return None. None is a special type in Python that represents nothingness. For example, it is used to indicate that a variable has no value if it has a value of None.

Every function implicitly contains a return None statement at the end unless you have written your own return statement. You can see this by running print someFunction() where the function someFunction does not use the return statement such as:
Supporting users have an ad free experience!