Lesson 1

Description

Basic Python commands and variable use
Joan L.
Flashcards by Joan L., updated more than 1 year ago
Joan L.
Created by Joan L. about 3 years ago
1
0

Resource summary

Question Answer
Define a string variable, example Variable = "cat"
Comment within a Python program, example #This is just a comment, and won't affect the program.
Variable with more than one word in it, example Many_words
Have a variable printed to the console, example Print (variable)
Have a string of text printed to the console, example Print ("This will print to the console.")
What will you see if you try to run the following, assuming you never defined any variables: Print (mycode) NameError
What will you see if you try to run the following: Print ("Hello, world') SyntaxError (for mismatched quote marks)
What sort of number would you define to find an average number? A float
What sort of number would you define if you were dealing with the number of guests at a party? An integer
Which keys perform the basic math operations? +, -, *, /
How is a variable changed in the middle of a program? It is simply redefined with an =, the same as when it was first defined.
How would you print 2 to the 4th power in Python? print (2 ** 4)
What is the % called, and what does it do? What is 10 % 4 in Python? It is called modulo, and it gives the remainder you get when you divide numbers. 2
What is it called when strings are printed together as a unit? String concatenation
Concatenate two strings, example new_string = oldstring1 + oldstring2
Concatenating a number variable with text strings, example message = string1 + string2 +str (numbervariable)
Use of the += function, example Variable1 += variable2 Variable1 will now equal the sum of its original value and variable2.
Using += to add a string String1 += "I want to add this"
How can we print longer strings that might include quote marks inside them that we don't want interpreted as code? """ This will be a longer string. It may cover many lines and "include quote marks." It won't end until three quote marks are entered to indicate the end of the long string. """
How would a user be prompted to define a variable? user_defined_variable = input ("Please define the variable, user.")
Show full summary Hide full summary

Similar

computer systems and programming quiz
Molly Batch
Python Quiz
karljmurphy
Think Python
tsilvo2001
French 1A Vocab
Jade Allatt
Memory: Multi-Store Model
jmclaughlin
Spanish No.1 Flashcards
Helena Hanley
Basic Economic Ideas
Li Xuan Law
Basic Python - Print Formatting
Rebecca Noel
What is Python?
Daniel Ingram
Learning and Study Skills
Salman Siddiqui
Adobe InDesign
Nicole Gentle