PyGenCon Flashcards

1
Q

Variable

A

A CONTAINER that stores data/values as a specific name

ie spam = 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

data type

A

numbers, text, booleens etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

whitespace

A

seperates statements

whitespace means right space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

comments

A

to make code easier to follow
# for single line comment
“"”for multi line comments”””

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

boolean

A

true or false statements

variables can store booleans
ie: a = true
b = false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Python order of operation

maths PEMDAS

A

python uses PEMDAS system:
Parentheses ( …) = everything in brackets first
Exponents ** = powers (5 ^ 3 is 5x5x5). written as 5 ** 5 in python
Multiplication
Division
Addition, Subtraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

modulo (Mod)

A

modulo returns the remainder from a division.

ie. 3%2 will return 1. 2 goes into 3 once with 1 remaining (remember the remaider is the bit modulo is interested in)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

String

A

A string is a data type which is written in “quotation marks” ie “ryan”
It can contain numbers, letters and symbols.
Each character in a string is assigned a number (the index) starting with 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

String method

A

lets you perform specific tasks for strings ie:
len() = length of string
str() = turns non-string into string ie. str(2) into “2”
. lower() = makes string all lowercase ie. “Ryan” .lower() into “ryan”
. upper() = makes string all uppercase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Dot Notation

A

this is strings with dot notation in!
ie “Ryan” .upper() or “Ryan”.lower()
but it could be one of many dot .() commands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

String Concatenation

A

This is combining strings with math operators

ie print “life + of + brian” becomes life of brian

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explicit String Conversion

A

converts non string to string ie:
print “I have” + str(2) + “coconuts!”
will print
I have 2 coconuts!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

String Formatting

A
printing a variable with a string
%s goes in the string
% goes after string
string1 = "Camelot"
string2 = "place"
print "let's not go to %s tis a silly %s" % (string1, string2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

3 ways to create string

A

‘Ryan’
“Ryan”
str(2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. print a string

2. advanced printing

A
  1. print “Hello” Hello
  2. g = “golf”
    h = “hotel”
    print “%s, %s” % (g, h)

golf hotel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are
datetime
and
datetime.now

A

datetime is a type of data (date and time).

datetime.now prints current date and time

17
Q

What are the “from” command and

“import” command

A

from = data location

import = get data

18
Q

What are hot commands and placeholders

in printing datetime context

A
placeholder = %s hot command = %
from datetime import datetime
now = datetime.now()
print '%s/%s/%s %s:%s:%s' % (now.day, now.month, now.year, now.hour, now.minute, now.second)
08/08/2014 13:56:23
19
Q

What is Control Flow

A

Enables code to make decisions

20
Q

What are the Control Flow Comparators

A
equal to ==
not equal to !=
less than <
greater than >
less than or equal to =
21
Q

What are Control Flow Expressions

A

expressions are values that can have operations like maths, boolean, if, or, and, not, nor, nand, etc.

18 >= 16
extreme expressions and comparators
(10 + 17) == 3 ** 16