Python Review Ex22

Card Set Information

Author:
Yongmin
ID:
169735
Filename:
Python Review Ex22
Updated:
2012-09-14 15:47:55
Tags:
python
Folders:

Description:
Review of Python symbols
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user Yongmin on FreezingBlue Flashcards. What would you like to do?


  1. print
    • Name: print
    • What it does: prints out string we input
  2. #
    • Name: octothorpe, pound, hash
    • What it does: allows you to comment on the code, anything after the # is ignored by python
  3. +
    • Name: plus
    • What it does: addition
  4. -
    • Name: minus
    • What it does: subtraction
  5. /
    • Name: slash
    • What it does: division
  6. *
    • Name: asterisk
    • What it does: multiplication
  7. %
    • Name: modulus
    • What it does: for math, it is the remainder of the division
  8. <
    • Name: less-than
    • What it does: Finds whether true or false whether X is less-than Y
  9. >
    • Name: greater-than
    • What it does: Finds whether true or false whether X is greater-than Y
  10. <=
    • Name: less-than-equal
    • What it does: Finds whether true or false whether X is less-than or equal-to Y
  11. >=
    • Name: greater-than-equal
    • What it does: Finds whether true or false whether X is greater-than or equal-to Y
  12. =
    • Name: single-equal
    • What it does: assigns value on the right to a variable on the left. Variables need to start with a character (not a number)
  13. ==
    • Name: double-equal
    • What it does: tests if two things have the same value
  14. "string %s" % variable
    • Name: format string
    • What it does: embed variables in a string using specialized format sequences, and putting variables at end with special syntax. If you want multiple formats in your string to print multiple variables, you need to put them inside a ( ) (parenthesis) separated by , (commas).
  15. %s
    • Name: s formatter
    • What it does: displays variables for users
  16. round()
    • Name: round function/command
    • What it does: rounds numbers
  17. '
    • Name: single-quote
    • What it does: putting two single-quotes around text creates a string
  18. "
    • Name: double-quote
    • What it does: putting two double-quotes around text creates a string
  19. %r
    • Name: r formatter
    • What it does: for debugging, displays the "raw" data of the variable. Also known as the "representation"
  20. %d
    • Name: d formatter
    • What it does: displays variables in decimal numery system for users
  21. """ or '''
    • Name: triple double- or single-quotes
    • What it does: allows you to create a string that only ends when you put another tripe double- or single- quote
  22. \\
    • Name: Backslash()
    • What it does: An escape sequence that inserts a backslash in a string
  23. \'
    • Name: single quote (')
    • What it does: An escape sequence that inserts a single quote in a string
  24. \"
    • Name: Double quote (")
    • What it does: An escape sequence that inserts a double quote in a string
  25. \a
    • Name: ASCII Bell (BEL)
    • What it does: An escape sequence that inserts a beep noise in a string
  26. \b
    • Name: ASCII Backspace (BS)
    • What it does: An escape sequence that inserts a backspace in a string
  27. \f
    • Name: ASCII Formfeed (FF)
    • What it does: An escape sequence that inserts a new page for a printer (and ejects current page) in a string ???
  28. \n
    • Name: Linefeed (LF)
    • What it does: An escape sequence that inserts a new line in a string
  29. \N{name}
    • Name: Character named name in the Unicode database (Unicode only)
    • What it does: An escape sequence that ???
  30. \r ASCII
    • Name: Carriage Return (CR)
    • What it does: An escape sequence that inserts a return in the string
  31. \t ASCII
    • Name: Horizontal Tab (TAB)
    • What it does: An escape sequence that inserts a horizontal tab in the string
  32. \uxxxx
    • Name: Character with 16-bit hex value xxxx (Unicode only)
    • What it does: An escape sequence that ??? in the string
  33. \uxxxxxxxx
    • Name: Character with 32-bit hex value xxxx (Unicode only)
    • What it does: An escape sequence that ??? in the string
  34. \v
    • Name: ASCII Vertical Tab (VT)
    • What it does: An escape sequence that inserts a vertical tab in the string
  35. \ooo
    • Name: Character with octal value ooo
    • What it does: An escape sequence that inserts a character with octal value ooo in the script
  36. \xhh
    • Name: Character with hex value hh
    • What it does: An escape sequence that inserts a character with hex value hh in the script
  37. ,
    • Name: comma
    • What it does: if inside a script, makes sure the print command doesn't end the line with a newline and go to the next one
  38. raw_input()
    • Name: raw input command
    • What it does: allows you to input a string into the script/code. You can also put a prompt within the parenthesis to show a person so they know what to type.
  39. int()
    • Name: integer command
    • What it does: converts user input into an integer
  40. input()
    • Name: input command
    • What it does: convert things you enter as if they were Python code, but has security problems so you should avoid it
  41. python -m pydoc x
    • Name: pydoc command
    • What it does: Python gives information on x
  42. from sys import argv
    • Name: script that accepts arguments
    • What it does: pass arguments as variables into script. Import allows you to add modules to your script from the Python feature set.
  43. import
    • Name: import command
    • What it does: adds modules to your script from the Python feature set
  44. argv
    • Name: argument variable
    • What it does: allows variables to hold arguments you pass to Python script when you run it. "Unpack" assigned variables to the left of the = argv in order. The user is required to give input arguments
  45. sys
    • Name: sys module
    • What it does: It is a "package" ???
  46. open()
    • Name: open command
    • What it does: opens the file for commands that you can give it. Without parameter the command opens file in 'r' (read) mode. The "w" parameter (filename, 'w') opens file in writing mode, and the 'a' paramter opens file in append mode. The + modifier expand the file modes: 'w+', 'r+', and 'a+' opens file in both read and write mode, and depending on character positions the file in different ways.
  47. read()
    • Name: read command
    • What it does: allows user to read file
  48. .
    • Name: dot or period
    • What it does: you give a file a command by using the period after the file, the name of the command, and the parameters of the command
  49. close()
    • Name: close command
    • What it does: closes the opened file
  50. readline()
    • Name: reads line command
    • What it does: reads just one line of a text file given parameters. Inside the command is code that scans each byte of a file until it finds a \n character, then stops reading the file to return what it found so far. The file in the parenthesis is responsible for maintaining the current position in the file after each readline() command.
  51. truncate()
    • Name: truncate command
    • What it does: empties the file
  52. write()
    • Name: write command
    • What it does: writes stuff in parenthesis into file
  53. from os.path import exists
    • Name:
    • What it does: imports the exists command from the os.path package
  54. exists()
    • Name: exists command
    • What it does: Based on the file's name in a string as an argument, the exists command returns True if a file exists and False if not.
  55. len()
    • Name: length command
    • What it does: gets the length of the string that you pass to it then returns that as a number
  56. def function_name(arguments)
    • Name: functions
    • What it does: Create functions by using def (define). We run/use/call functions. Function names cannot start with numbers.¬†Functions do three things. 1) Name pieces of code the way variables name strings and numbers. 2) Take arguments the way your scripts take argv. 3) Allows you to make your own "mini scripts" or "tiny commands". The lines after the first in the function script must be indented 4 spaces. To end the function script you must "dedent". Use *args (asterisk args) in the parenthesis to have same use as the argv parameter but for functions. Must end the def line with a colon, and then indent. ¬†The variables in functions are not connected to variables in the script.
  57. seek()
    • Name: seek command
    • What it does: Files in Python has a "read head", and you can "seek" this read head around the file to different positions. Each time you do seek(0), you're moving to the start of the file. The seek command is dealing in bytes (not lines). The 0 byte is the first byte in the file.
  58. +=
    • Name: plus minus
    • What it does: contraction for two operations = and +. x = x + y is the same as x += y.
  59. return
    • Name: return
    • What it does: allows variables to be a value from a function

What would you like to do?

Home > Flashcards > Print Preview