Python Intro/Syntax Flashcards

1
Q

Basic Python Syntax rule:

A

Capitalization matters

Each statement on one line, by itself

Indentation matters!!!

Quotes around strings like “red”, no quotes around numbers

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

understanding errors:

A

Tip: read Python’s helpful error message and check for typos

SyntaxError: invalid syntax

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

what is print?

A

is a function used to display values placed inside the parentheses ( )

print(“Hi”)
print()
print(“How are you”)
“How are you” is a value that’s a string (a string of text)

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

what is comment?

A

great for annotating and adding notes to your source code.
# ##Todo: eventually I should remove the line below…
# It’s fine for now tho
“””
this is only note
“””
You can have multiple comments — as many as you want!

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

What is Value?

A

is a piece of data.

Values belong to categories called data types

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

Data types

A
String - "Hello, world!", "!"
Integer - 1, 54679
Float - 3.14, -1.6
Boolean - True, False
None - None
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Variables

A

are used to store values so you can use them later

greeting = “Hello, world!”

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

what is =?

A

is a assignment operator

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

How to create a variable?

A

Valid characters are letters, numbers, and underscores

don’t start with a number

num_students
book_titles

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

concatenate

A

The act of adding one string to another with + can be referred to as string concatentation.

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

Strings

A

A string that’s an entire sentence, one character, symbols and numbers and surrounded by quotation marks.
“Hello, world!”
“a”
“! 3&*# 29”
You can use single quotes (‘) or double quotes (“)
But take care not to mismatch them!

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

Integers

A

are whole numbers that can be signed (negative) or unsigned (positive)

A positive integer: 100
A negative integer: -1568
Can separate digits with underscore: 100_000
You can perform mathematical operations on integers.

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

Integer operator:

A

Add +
Subtract -
Multiply *
Divide /

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

integer sample:

A

Adding integers together
my_score = 100 + 5
print(my_score)

num_attendees = 5
total_prizes = 20
print(total_prizes / num_attendees)

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

Floats

A

AKA floating-point numbers
They’re non-whole numbers (they can have a decimal point)

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

Booleans

A

The Boolean data type has just two members:

True

False

sleepy = True
print(sleepy)
>True

17
Q

More Booleans samples:

A
sleepy = False
if sleepy:
    print("YAWN! x(")
else:
    print("I'm awake :)")

> I’m awake :)

18
Q

None

A

There’s only one value that’s a None-type — None

It represents the idea of nothingness, ex.: a missing value

fav_sport = None
You’ll learn more about it later — for now just know it exists.