You are on page 1of 5

Chap 2 and 5 Python

Chapter Two Variables


1: what is Variables?
❖ Are references to objects
• Are not declared, just assigned
• Everything in Python is an object
• Variable types don’t need to be declared.
• Python figures out the variable types on its own.
2: what is the basic printing command?
❖ is “print.”
3: Logical operators are words such as?
❖ (and, or, not) not symbols (&&, ||, !).
4: Start comments of Python?
❖ is #
5: Python Build-in types?
❖ Numbers 3.1415
❖ Strings “Hello World”
❖ Lists [1,2,3,4]
❖ Dictionaries {‘test’: ‘yum’}
❖ Files input=open(‘file.txt’, ‘r’)
6: Python string?
❖ is the next major build-in type is the Python --- an ordered collection of characters to
store and represent text-based information
❖ Python strings are categorized as immutable sequences --- meaning they have a left-to-
right order (sequence) and cannot be changed in place (immutable)
❖ Characters in a string are numbered with indexes starting at 0
7: Examples of Strings?
❖ "hello"+"world" "helloworld" # concatenation
❖ "hello"*3 "hellohellohello" # repetition
❖ "hello"[0] "h" # indexing
❖ "hello"[-1] "o" # (from end)
❖ "hello"[1:4] "ell" # slicing
❖ len("hello") 5 # size
❖ "hello" < "jello" 1 # comparison
❖ "e" in "hello" 1 # search
❖ New line: "escapes: \n "

pg. 1
Chap 2 and 5 Python
❖ Line continuation: triple quotes ’’’
❖ Quotes: ‘single quotes’, "raw strings"
8: what is raw input?
❖ Reads a string of text from user input.
9: Python Objects: Lists, Tuples, Dictionaries?
❖ Lists (mutable sets of strings)
• var = [] # create list
• var = [‘one’, 2, ‘three’, ‘banana’]
❖ Tuples (immutable sets)
• var = (‘one’, 2, ‘three’, ‘banana’)
❖ Dictionaries (associative arrays or ‘hashes’)
• var = {} # create dictionary
• var = {‘lat’: 40.20547, ‘lon’: -74.76322}
• var[‘lat’] = 40.2054
10: How Tuples, Lists, and Strings are defined?
❖ Tuples are defined using parentheses (and commas).
❖ Lists are defined using square brackets (and commas).
❖ Strings are defined using quotes (“, ‘, or “““).
11: The ‘in’ Operator in containers?
❖ Boolean test whether a value is inside a container:
>>> t = [1, 2, 4, 5]
>>> 3 in t
False
12: Lists are the most flexible containers?
❖ Lists are Python’s most flexible ordered collection object type
❖ Lists can contain any sort of object:
• numbers,
• strings and even other lists
• Ordered collection of data
• Data can be of different types
• Lists are mutable
• There are issues with shared references and mutability
• Lists have the same subset operations as Strings

pg. 2
Chap 2 and 5 Python
13: Tuples?
❖ A tuple is an ordered collection which cannot be modified once it has been created.
❖ In other words, it's a special array, a read-only array.
❖ Like a list, tuples are iterable arrays of objects
❖ Tuples are immutable –once created, unchangeable
❖ To add or remove items, you must redeclare
❖ Example uses of tuples
• County Names
• Land Use Codes
• Ordered set of functions
14: Dictionaries?
❖ Dictionaries are sets of key & value pairs
❖ Refer value through key; “associative arrays”
❖ Allows you to identify values by a descriptive name instead of order in a list
❖ Keys are unordered unless explicitly sorted

END

pg. 3
Chap 2 and 5 Python
Chapter Five GUI PROGRAMMING
1: what is Tcl?
❖ is a Tool Command Language
❖ invented in 1990
❖ used for web and desktop applications, networking, administration, scripted
applications, embedded system, rapid prototyping and testing.
2: TKINTER = Tcl + Tk?
❖ Tk
• A GUI toolkit provided as a library of C routines.
• This library manages and manipulates the windows and
• handles the GUI events and user interaction.
❖ Tkinter
• The Python Tkinter interface is desktop Application which helps us to interact
with computers as clinking. A Python module that provides a collection of Python
classes and methods.
❖ Tcl
• Is the (mostly hidden) language used by Tk and, hence, used by Tkinter to
communicate with the Tk toolkit.
3: List five main steps that are required to get your GUI up and running?
❖ Import the Tkinter module (or from Tkinter import *).
❖ Create a top-level windowing object that contains your entire GUI application.
❖ Build all your GUI components (and functionality) on top (or within) of your top-level
windowing object.
❖ Connect these GUI components to the underlying application code.
❖ Enter the main event loop.
4: Windows and Widgets?
❖ In GUI programming, a top-level root windowing objectcontains all of the little
windowing objects that will be part of your complete GUI application. These can be text
labels, buttons, list boxes, etc. These individual little GUI components are known as
widgets.
5: Top-level windows?
❖ are those that show up stand-alone as part of your application. You can have more than
one top-level window for your GUI, but only one of them should be your root window.

pg. 4
Chap 2 and 5 Python
6: Geometry Managers?
✓ Tk has three geometry managers that help with positioning your widgetset
❖ Placer:-You provide the size of the widgets and locations to place them; the manager
then places them for you.
❖ Packer:- it packs widgets into the correct places (namely the containing parent widgets,
based on your instruction), and for every succeeding widget,
❖ Grid:- It is used to specify GUI widget placement, based on grid coordinates.
7: list Standard attributes?
❖ Dimensions
❖ Colors
❖ Fonts
❖ Anchors
❖ Relief styles
❖ Cursors
8: what is Event-Driven Processing?
❖ Is the entire system of events that occurs from the beginning until the end of a GUI
application is what drives it.
❖ One example of an event with a callback is a simple mouse move.
9: Event Handling?
✓ Event sources (widgets) can specify their handlers
❖ command handlers
❖ callbacks
10:callback?
❖ callback is the name of the function that is to be run in response of an event
❖ callbacks can be defined as a free standing function in our program
11: command handlers?
❖ is a library for Flask framework which provides: API (application programming
interface) method for posting new commands, tools for easy command handlers
management.
END

pg. 5

You might also like