Syntax Flashcards Preview

Beginning Python > Syntax > Flashcards

Flashcards in Syntax Deck (10):
1

What is an Identifier

it is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore followed by zero or more letters, underscores and digits. Python is case sensitive.

2

Do class names start with an upper or lowercase letter

Uppercase

3

How do you form a multi line statement

This is done with the line continuation character ( \ )

total = item_one + \
item_two + \
item_three

4

How is quotation used in Python

Python accepts sing('), double(") and triple (''' or """) quotes to denote string literals, so long as the same type of quote starts and ends the string.

5

How are triple quotes used ( """ )

Triple quotes are used to span the string across multiple lines.

paragraph = """This is a paragraph. It is
made up of multiple lines and sentences."""

6

What does the hash sign do ( # )

The hash sign tells python to ignore that section of code.

7

How does Python handle a blank line?

Python ignores this whitespace

8

How do you allow for multiple statements on a single line?

The semicolon ( ; ) allows multiple statements on a single line given that no statement starts a new code block.

import sys; x = 'foo'; sys.stdout.write(x + '\n')

9

What are groups of individual statements called?

These are called suites. Compound or complex statements, such as if, while, for, def, and class require a header line and a suite.

10

What is in a header line?

Header lines begin the statement (with the keyword) and terminate with a colon ( : ) and are followed by one or more lines which make up the suite.

if expression :
suite
elif expression :
suite
else :
suite