Section 1

Preview this deck

%s

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 (51)

Section 1

(50 cards)

%s

Front

String A string is intended for general consumption. use %s (string) for anything that you want to show to an end user

Back

%f

Front

float Floating point decimal format

Back

"

Front

Every time you put " (double-quotes) around a piece of text you have been making a string. A string is how you make something that your program might give to a human. You print strings, save strings to files, send strings to web servers, and many other things. ' (single-quotes) also work for this purpose.

Back

\'

Front

Single-quote (')

Back

%d, %i

Front

Signed integer decimal

Back

\v

Front

ASCII vertical tab (VT)

Back


Front

ASCII linefeed (LF) - new line

Back

\"

Front

Double-quote (")

Back

\a

Front

ASCII bell (BEL)

Back

\xhh

Front

Character with hex value hh

Back

True False

Front

Python recognizes True and False as keywords representing the concept of true and false. If you put quotes around them then they are turned into strings and won't work.

Back

%d

Front

digit

Back

''',"""

Front

Free-form strings

Back

open()

Front

opens the specified file, it takes a parameter and returns a value you can set to your own variable.

Back

How do I get a number from someone so I can do math?

Front

That's a little advanced, but try x = int(raw_input()) which gets the number as a string from raw_input() then converts it to an integer using int()

Back

%e

Front

Floating point exponential format

Back

%r

Front

Raw string Representation: A representation is something that (might?) allow for some sort of round-trip, later (re)construction of the object. use %r if you are planning to (re-)consume your own printed output. You should use %s and only use %r for getting debugging information about something. The %r will give you the "raw programmer's" version of variable, also known as the "representation." prints the way you wrote it (or close to it).

Back

from sys import argv

Front

Called an "import." This is how you add features to your script from the Python feature set. Rather than give you all the features at once, Python asks you to say what you plan to use. This keeps your programs small, but it also acts as documentation for other programmers who read your code later. May access features other than "argv"

Back

\N{name}

Front

Character named name in the Unicode database (Unicode only)

Back

\ooo

Front

Character with octal value ooo

Back

\Uxxxxxxxx

Front

Character with 32-bit hex value xxxxxxxx (Unicode only)

Back

"""

Front

Use to make a string that needs multiple lines for the string text.

Back

PEMDAS

Front

Order of Operations: Mode of Operations: Parentheses Exponents Multiplication Division Addition Subtraction

Back

round()

Front

rounds the value contained in the ()

Back

\

Front

Escape What It Does: This \ (backslash) character encodes difficult-to-type characters into a string. There are various "escape sequences" available for different characters you might want to use. We'll try a few of these sequences so you can see what I mean. An important escape sequence is to escape a single-quote ' or double-quote ". Imagine you have a string that uses double-quotes and you want to put a double-quote inside the string. If you write "I "understand" joe." then Python will get confused because it will think the " around "understand" actually ends the string. You need a way to tell Python that the " inside the string isn't a real double-quote. To solve this problem you escape double-quotes and single-quotes so Python knows to include in the string. Here's an example: "I am 6'2\" tall." # escape double-quote inside string 'I am 6\'2" tall.' # escape single-quote inside string The second way is by using triple-quotes, which is just """ and works like a string, but you also can put as many lines of text as you want until you type """ again. We'll also play with these.

Back

.read()

Front

reads the specified file use by entering at the end of the variable used to specify the file you have 'opened'.

Back

Write comments on code ...

Front

No, you write comments only to explain difficult to understand code or why you did something. Why is usually much more important, and then you try to write the code so that it explains how something is being done on its own. However, sometimes you have to write such nasty code to solve a problem that it does need a comment on every line. In this case it's strictly for you to practice translating code to English.

Back

=

Front

(single-equal) assigns the value on the right to a variable on the left.

Back

variables

Front

can only start with a character (not a number)

Back

\f

Front

ASCII formfeed (FF)

Back

import

Front

This is how you add features to your script from the Python feature set. Rather than give you all the features at once, Python asks you to say what you plan to use. This keeps your programs small, but it also acts as documentation for other programmers who read your code later.

Back

\b

Front

ASCII backspace (BS)

Back

int()

Front

converts to integer

Back

==

Front

(double-equal) tests if two things have the same value.

Back

"""

Front

Back

%x

Front

Signed hexidecimal

Back

\\

Front

Backslash (\)

Back

%

Front

Modulus is NOT used as a "percentage" sign in the programming language

Back

\t

Front

Horizontal Tab (TAB) - Tab In

Back

Floating Point Number

Front

any number with a decimal point showing one or more digits behind the decimal point. e. "4.0" or "0.087"

Back

%c

Front

Single character

Back

raw_input()

Front

Use for asking a user questions. Creates a dialogue that asks for a user to input data. Use to create "forms". input() has security problems, so avoid using it For raw_input you can also put in a prompt to show to a person so he knows what to type. Put a string that you want for the prompt inside the () so that it looks like this: y = raw_input("Name? ")

Back

\r

Front

Carriage Return (CR)

Back

argv

Front

the "argument variable," a very standard name in programming, that you will find used in many other languages. This variable holds the arguments you pass to your Python script when you run it. You know how you type python ex13.py to run the ex13.py file? Well the ex13.py part of the command is called an "argument." What we'll do now is write a script that also accepts arguments. What's the difference between argv and raw_input()? The difference has to do with where the user is required to give input. If they give your script inputs on the command line, then you use argv. If you want them to input using the keyboard while the script is running, then use raw_input(). Line 3: script, first, second, third = argv Line 3 "unpacks" argv so that, rather than holding all the arguments, it gets assigned to four variables you can work with: script, first, second, and third. This may look strange, but "unpack" is probably the best word to describe what it does. It just says, "Take whatever is in argv, unpack it, and assign it to all of these variables on the left in order." (ex13.py)

Back

modules

Front

libraries or features

Back

#

Front

Octothorpe use for comments on the code, use to disable code placing a # at the beginning of a line or in the middle of a line tells python to ignore whatever is written on the line after the #

Back

strings

Front

A string is usually a bit of text you want to display to someone, or "export" out of the program you are writing. Python knows you want something to be a string when you put either " (double-quotes) or ' (single-quotes) around the text. You saw this many times with your use of print when you put the text you want to go inside the string inside " or ' after the print to print the string. Strings may contain the format characters you have discovered so far. You simply put the formatted variables in the string, and then a % (percent) character, followed by the variable. The only catch is that if you want multiple formats in your string to print multiple variables, you need to put them inside ( ) (parenthesis) separated by , (commas). It's as if you were telling me to buy you a list of items from the store and you said, "I want milk, eggs, bread, and soup." Only as a programmer we say, "(milk, eggs, bread, soup)."

Back

,

Front

We put a , (comma) at the end of each print line. This is so print doesn't end the line with a newline character and go to the next line

Back

%o

Front

Signed octal value

Back

\uxxxx

Front

Character with 16-bit hex value xxxx (Unicode only)

Back

Section 2

(1 card)

.

Front

give a file a command ex: .read() What you get back from open is a file, and it also has commands you can give it. You give a file a command by using the . (dot or period), the name of the command, and parameters. Just like with open and raw_input. The difference is that txt.read() says, "Hey txt! Do your read command with no parameters!"

Back