Python

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the syntax for multiple line strings in python?

""" triple quotes

Individual characters of a string in python can be accessed with ?

([ ]) square brackets str = "Hello" print(str[1]) #e print("ABCD"[0]) #A print(str[-1]) #o

How many of these are true? 1) Python is case‐sensitive. 2) A command in Python is terminated by a semi‐colon. 3) Indentation does not matter in Python. 4) A single line comment starts with """. 5) The print command prints to standard input.

-1 python is case sensitive is the only true statement. -print command prints to the terminal

*Who developed Python and when was it released?

-Guido van Rossum and fist released in 1991. -2.0 released in 2000 and backwards incompatible 3 in 2008 -name doesn't refer to Monty Python

What Esther operator precedence in python?

1) parentheses (inner most and then outer) 2)exponents 3)multiplication and division 4) addition and subtraction

How many of the following variable names in python are valid? 1) name 2) string2 3) 2cool 4) under_score 5)spaces name 6) else

3 are correct: name, string2, and under_score

When there is block in python how many spaces should you use for indentation?

4 spaces

How many of the following are valid Python strings? 1)"" 2)'' 3)"a" 4)" " 5)""" 6)"Joe\' Smith\""

5 are correct: """ is the only one that is not correct -last one "Joe\' Smith\"" is correct because it escaped the double quote at the end

What math expression is this % in python?

9 % 4 (answer is 1) Divides left hand operand by right hand operand and returns remainder

What is the output of this code? st1 = "Hello" st2 = "World!" num = 5 print(st1 + str(num) + " " + st2)

Hello5 World!

When is the end of a command on python?

at the end of a line, there is no terminator like a semi-colon

What math expression is this ** in python?

exponent 5**2 (answer is 25)

string to integer in python

int(" ") int('"9") output is 9

Length string function python

len (variable) need to use a comma before to print the number because it Is number and not a string, down use + len ()

What is the general cod for the print function in python? Where does the print function print?

print("text") print(variable) -print will print to the terminal (standard output) whatever data (number, string,variable)

What code do you need to use when there is a aposphrope in string in python?

use \ to escape "There\'s

concatenation in python

variable + variable must put a " " in-between variables if want a space

substring in python

variable [#:#]

What are the rules for variable names in python?

-must begin with a letter and cannot have spaces -variables created when they are first used, no special syntax to create a variable -case sensitive -numbers allowed but not at start and underscores __ are allowed -avoid reserved words: if, for, else

convert to a string in python

str ( ) str (9) output is "9" must do this for numbers when you want to add them to a print function of a string

upper and lower case string function python

variable.upper ( ) variable.lower ( )

Rules of python printing

-have to do a separate print function for each line of code printed

*What is Python?

-a general, high-level programming language designed for code readability and simplicity. -open source and has a large community supporting its development

What is a variable in python?

-a name that refers to a location that stores a data value -value at a location can change using initialization or assignment (=)

Define algorithm, program and language

-algorithm is a precise sequence of steps to produce a result. -program is an encoding of an algorithm -language solves the particular problem

What are the Python Core Philosophies (5) ?

-beautiful better than ugly -explicit better than implicit -simple better than complex -complex better than complicated -readability counts

What are the Python Language Characteristics (4)?

-dynamic typing(can change while running) -multi-paradigm(procedural, object-oriented, functional styles) -auto memory + garbage collection -extendable(small core language + easily extendable)

What are the rules for strings in python?

-surrounded by single or double quotes -cannot have enter, backspace,tab and backslash \n is a new line \' single quote \\ backslash \" double quote -double quote strings can have single quotes in them and vice versa -any number of characters can be used -min number of characters is 0 = empty string -string literals (values) have quotation marks removed when displayed

Is python case sensitive?

Yes

Is python particular on whitespace and indentation?

Yes

What is the notation for multiple line comments in python?

put """ at start and end

What is the notation for one line comments in python?

put # before the comment and any characters to the end of line are ignored # Single line comment print (1) # Comment at end of line


संबंधित स्टडी सेट्स

Cell division Homework #1 - Mrs.Brya

View Set

Chapter 7 A&P in class assignment

View Set

Chapter 10 Understanding Work Teams

View Set

Test 2 Fundamentals of Marketing and Technology

View Set

Porth's CH 40 Disorders of Acid-Base Balance

View Set