Programming 1: Python Chapters 1 & 2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Line Continuation Character

"\" separates lines

Modulus

% gives remainder of division

Integer division

// - rounds to an integer

Naming Variables

1. Can only contain numbers, letters, and underscores 2. A variable can't start with a number

Printing a Backslash

2 backslashes print one backslash

Function

A named collection of programming code that can receive values, do some work, and return values

Float

A numeric type for numbers that have a fractional part

Integer

A numeric type for numbers that have no fractional part

High Level Language

A programming language closer to human language than machine language

String

A sequence of characters

Code

A sequence of programming statements. Also called source code

Escape Sequence

A set of characters that allow you to insert special characters into a string

Augmented Assignment Operator

A shortcut used when assigning a new value to a variable based on its original value x*=5 x=x*5

Statement

A single unit in a programming language that performs some action when executed

Assignment Statement

A statement that assigns a value to a variable and creates the variable if necessary

Triple Quoted String

A string that is bounded by three instances of either the double quote mark (") or the single quote mark ('). It allows strings to continue over multiple lines and displays output exactly as the programmer enters it

Argument

A value needed for a function that is placed in ()

Console Window

A window that can only display text

Syntax Highlighting

Colors of the words on the screen Special words - purple Strings - green Output - blue

Specifying a Final String to Print

Comma, followed by end, =, and final string

Where can you find Python for free?

Companion website

backslash \

Continues a statement onto the next line

lower()

Converts a string to all lower case print(quote.lower())

upper()

Converts a string to all upper case print(quote.upper())

title()

Converts a string where the first letter of each word is capitalized and the rest of the string is in lower case print(quote.title())

Logical Error

An error that doesn't cause a program to crash, but instead produces unintended results

Syntax Error

An error that results from a statement that does not conform to the rules of usage. Often, a syntax error is the result of a typo

Interactive Mode

Ask and get response immediately (single line)

float()

Converts into a float

Major Goal of Python

Bridge the gap between the programmer's brain and the computer

print Function

Display text surrounded by quotes

Why use blank lines?

Easier to read program

Single and Double Quotes

Either can be used with a print statement to display a string. Can also be used to display a set of quotes by using the opposite inside the quotes - i.e. print "Program 'Game Over' 2.0"

Comments

Explain code in English (or another language) Ignored by computer

Saving

File -> save as -> and .py

input () Function

Get info from user name = input("")

input()

Get some text from the user

Programming

Getting your computer to do stuff

Pass

Give a function values to work with

Companies that use Python

Google, IBM, NASA, Microsoft, and Yahoo!

Who created Python? When?

Guido van Rossum in 1991

Single & Double Quotes

If you need quotes in side then use "" to mark ending and beginning and '' for the quote inside

\n

Inserts a new line

Python Shell

Interactive mode in python

Concatenating

Joining strings to make new string , but there are no spaces or separators

Moving Forward a Tab Stop

Just use tab inside "" to space print (" tab string") -> __tab__string

Call

Kick off a function using the function name

How do you keep the console window open?

Last line of code input ("\n\nPress enter to exit")

Object Oriented Programming

Method of representing information and actions in a program

\t

Moves forward one tab stop

Invoking a string method

Must be used with a string. Add a dot, followed by the name of the method

Running

Need to save it in order for it to run

Comment

Note in source code meant only for programmers. Often used to clarify code or introduce a new code section (uses #)

Floats

Numbers with decimal point

Why are comments useful in the "real world"?

Other programmers can modify your program

Function Nesting

Placing one function call inside another. The return value of the inner function acts as an argument for the outer function

Platform Independent

Program will run on different computers with Python

Variable

Provides a way to label and access information

Escape Sequences

Put special characters into strings Backslash by a character \t\t\t creates space (______string_______)

Nesting

Putting one function inside another

What is a "glue" language?

Python can be integrated with other languages

2 Modes in IDLE

Script and Interactive

Expression

Sequence of values joined by an operator

Development Environment (IDLE)

Set of tools that makes writing programs easier

Creating Triple Quoted Strings

Span multiple lines

int()

Takes the string referenced and returns an integer version of it int(input())

Arguments

The stuff in between the ()

Concatenate

To join together

Script Mode

Write, edit, load, and save a program

Printing Multiple Values

You can start a new line after each ,

Sounding the System Bell

\a makes bell noise

Inserting a New Line

\nsting prints a blank line then sting

String Methods

allow you to create new strings from old ones (doesn't change what the actual phrase is)

Last line of code

input ("\n\nPress the enter key to exit.")

3 things that can be in a variable's name

letters, numbers, underscore

replace()

print(quote.replace("five", "millions of"))

Repeating Strings

sting * amount

Inserting a Quote

to print "can't" do print (\"can\'t\")


Ensembles d'études connexes

creative thinking and innovation

View Set

Adult Health Chapter 44: Nursing Management: Patients With Oncologic Disorders of the Brain and Spinal Cord

View Set

difference between apoptosis and necrosis

View Set

PL-RI-1 Introducción a Redes de Telecomunicaciones

View Set

Maternity Exam 3 Cumulative Review Questions

View Set

تطبيقات شبكات الحاسب الوحدة الأولى: مقدمة عن الشبكات ونظام التشغيل الخادم 2008

View Set

chapter 22 assessment of the integumentary system

View Set

Unit 5: Industrialization and Qing & Meiji Restoration

View Set