Python Assessment and Python Keywords, Concepts, Functions: Difference between pages

From Computer Science at Indiana State University
(Difference between pages)
Jump to navigation Jump to search
m 1 revision imported
 
wiki_previous>Jkinne
 
Line 1: Line 1:
The C assessment exam has used questions on specific topics, often those in the following list.  
Following are terse descriptions for Python3 keywords, programming concepts, and commonly used functions.  For more information, see [https://www.w3schools.com/python/python_ref_keywords.asp w3schools] for a bit more explanation and [https://docs.python.org/3/reference/ python.org] for the language reference.
# Simple and nested loops.  
# Functions
# Bit operations
# Linked list
# Binary trees


This page is an attempt to identify such a set of topics for Python. The focus is on fundamentals, not modules. No imports allowed.
=Keywords=
For each problem type, some topics are listed. Then example problems are given (or will be someday), and split into three categories: Easy, Medium, and Hard. A typical exam might use one each from the Easy and Hard categories, and three from the Medium category.
The following are heavily used in all levels of Python programming.  This is a minimum set of keywords to know how to use.
* <code>break</code> - exit the current loop
* <code>continue</code> - in a loop, go to next iteration of the loop
* <code>is</code> - determine whether two objects are the same object (not just value)
* <code>import, from</code> - to load a module
* <code>def</code> - declare a function
* <code>while</code> - loop with only condition
* <code>if, elif, else</code> - conditional statements (three keywords)
* <code>for</code> - loop with that iterates through a list
* <code>return</code> - keyword to send a value back from a function
* <code>and</code> - boolean operator, True only if both sides are True
* <code>or</code> - boolean operator, True if either side is True
* <code>not</code> - boolean operator, negates
* <code>True, False</code> - boolean values (two keywords)
* <code>del</code> - remove from a list by position
* <code>try, except</code> - handle an exception, basic use (2 keywords)
* <code>raise, assert</code> - raise/indicate an exception (2 keywords)
* <code>in</code> - test if something is inside of a list/string/tuple/dictionary
* <code>None</code> - special value for a variable that has no value
* <code>pass</code> - empty statement that does not do anything


= Basic (BASIC) level programs =
==More Keywords==
== Topics ==  
These keywords are often not introduced or heavily used until the second Python course.
# Basic data types: string, numeric (not Complex), Boolean
* <code>as, finally, with, else</code> - exception handling, more keywords (4 keywords)
# Reading and writing: input and print.
* <code>class</code> - defining new class data type (for object-oriented programming)
# Type conversions: string to/from numeric.
* <code>lambda</code> - create unnamed / anonymous function
# Algebraic expressions. Assignment statements.
* <code>global, nonlocal</code> - access variables outside of current scope (2 keywords)
== Problems ==
* <code>async, await</code> - for writing asynchronous code with asynchio package (2 keywords)
# Easy: Celsius to Fahrenheit conversion.
* <code>yield</code> - for creating generator functions
# Medium: Temperature conversion with inputs like: 30F, 40C, etc.
# Harder: Real solutions to quadratic equations.


= Fundamental Data Structures =
=Concepts=
List, tuple, set, frozenset, dictionary
''See [https://youtu.be/rB8jY3Y54_A this video] for a demo and explanation of basic data types and variables.
== Topics ==
''
# Creation of, and basic operations on, all five data structures.
# Slicing.
# Selecting the appropriate data structure.
# Comprehensions.
== Problems ==
# Easy: Find words common to two lists, read from 2 column data .le.
# Medium: Find words common to two of three lists.
i# Medium: Multiple choice? A few scenarios, pick the data structure: Example: Look­ing up words in a foxed list of words. Which of the five do we use? Or, looking up words in a changing list of words. Looking up and counting frequencies for a list of words.  
# Harder (Code golf with comprehensions?) Sort, max, min problems. Example: Sort a list of words by the number of vowels in the word. Example: Find the number (in a list) with the most one bits in its binary representation.


= Functions =
These are terms that we use to describe programs.  These are terms that have a precise meaning when talking about programs.
== Topics ==
* '''string''' - text data type
# Basic definition.  
* '''boolean''' - data type for True and False
# Test knowledge of builtin functions.  
* '''floating point''' - data type that stores numbers with fractional parts (e.g., 3.14 or 2.2)
# Recursion.  
* '''integer''' - data type that stores only integers
# Decorators? Move this to classes?
* '''<code>None</code>''' - a special value in Python that means "nothing" but is different than 0, False, and ""
== Problems ==
* '''variable''' - name for a place in memory to store values.  Two basic things you do with a variable - (i) store a value into the variable, (ii) get the value from the variable.
# Easy: Defining simple functions. Position and named parameters.  
* '''keywords''' - also called ''reserved'' words - these are names that should not be used for variable names because they have special meaning to python.  Example: <code>for</code> is used for loops and shouldn't be used as a variable name.
# Medium: Recursion with memoization (functools not allowed).  
* '''function''' - also called ''procedures'' or ''methods'' - name for a block of code that does something and that your code can use when needed.  Two basic things you can do with a function - (i) define what the function is (specify the code for the function), (ii) call the function later on in your code.  Three main parts of defining function - (a) function code (called the ''body''), (b) function ''parameters'' (aka input variables), (c) function return values.  Three main parts of calling/using a function - (1) specify the ''arguments'' to the function (which are passed in to the parameters of the function), (2) ''call'' the function, (3) get the ''return'' value of the function.  Note that the ''function prototype'' refers to the line that declares the function, which has the function name, return type, and list of parameters to the function.  When a function is called, the arguments to the function are ''passed'' to the function (parameter variables are set equal to the arguments).
# Hard: Functions returning functions: return a linear or quadratic function given coefficients.  
* '''flow chart''' - diagram that shows the steps / flow of control in a program (also used to diagram decision-making in other settings - e.g., diagnosis of an illness, managing a factory, ...)
* '''binary operator''' - operator that takes two values to produce a result.  An example is addition, 2 + 3 results in 5.  Another example is == comparison, 'hi' == 'bye' results in False because the two are not equal.
* '''unary operator''' - operator that takes one value to produce a result.  An example is Boolean not, not True results in False.
* '''operator precedence''' - rules for which operators are evaluated first in an expression.  For example, in 1 + 2 * 3, the multiplication is performed first, giving 1 + 6, and then the + is performed to result in 7.  For Python, see [https://docs.python.org/3/reference/expressions.html#evaluation-order python.org].
* '''operator associativity''' - rule whether operators of the same type are evaluated left-to-right or right-to-left.  Math operators are left-to-right.  For Python, see [https://docs.python.org/3/reference/expressions.html#evaluation-order python.org].


= Iterators and Generators =
=More Information=
== Topics ==
[https://docs.python.org/3/library/stdtypes.html Python built-in types] - includes information on operations that come along with the builtin types.
# Using iterators: for, next, iter.  
# Common iterators: lists, tuples, dictionaries, range, zip, enumerate, .le descriptors, et cetera.  
# Creating iterators: class-based iterations (move to classes?).
== Problems ==
# Easy: nested loops, one of Rob’s patterns of characters.
# Medium: nested loops, one of Rob’s harder patterns.
# Medium: Given class definition: write a method to do something.
# Hard: (generators) Construct generator for words from text .le.  


= Classes =
=Commonly Used Functions=
== Topics ==
* <code>print</code> - function to write to the screen
# Basic definition.
* <code>int, float, str</code> - functions to convert to integer, floating point number, or string
# Dunder methods, class based iterators.
* <code>range</code> - function to generate a sequence of numbers
# Inheritance. Decorators.
* <code>len</code> - function to get the length of a string, list, or tuple
# Privacy conventions.
* <code>open, read, write, close</code> - functions for reading/writing text files and options 'r', 'w', 'a' for open
== Problems ==
* string methods - <code>isalpha</code>, <code>isdigit</code>, <code>split</code>, <code>join</code>
# Easy: De.ne a Point class; add a few methods for distance, norms.
* list methods - <code>sort, index, append, remove, copy</code>
# Medium: Binary tree class, with the usual methods, a couple dunders (in, len, str, add, eq, invert).  
* tuple methods - <code>index, count</code>
# Hard: Subset frequency counting trie. Given a big set, .nd all subsets that appear as subsets in at least r of the sets.
* dictionary methods - <code>keys, values, items</code>
* syntax for using strings, lists, tuples dictionaries -
* methods in random module - <code>randint, shuffle</code>
* methods in sys module - <code>exit, argv</code> list
* methods from the copy module - <code>copy.deepcopy</code>
 
=Assignment=
It is traditional to have a quiz where you must properly be able to identify all Python keywords and data types.  A quiz that you can practice with is - [https://indstate.instructure.com/courses/12565/quizzes/228163?module_item_id=1145854 Python Keywords and Data Types Quiz].
 
'''Pass rating check''' If you are assigned this quiz in a course, you should be able to get 100% once you get comfortable with Python.

Revision as of 15:36, 7 September 2022

Following are terse descriptions for Python3 keywords, programming concepts, and commonly used functions. For more information, see w3schools for a bit more explanation and python.org for the language reference.

Keywords

The following are heavily used in all levels of Python programming. This is a minimum set of keywords to know how to use.

  • break - exit the current loop
  • continue - in a loop, go to next iteration of the loop
  • is - determine whether two objects are the same object (not just value)
  • import, from - to load a module
  • def - declare a function
  • while - loop with only condition
  • if, elif, else - conditional statements (three keywords)
  • for - loop with that iterates through a list
  • return - keyword to send a value back from a function
  • and - boolean operator, True only if both sides are True
  • or - boolean operator, True if either side is True
  • not - boolean operator, negates
  • True, False - boolean values (two keywords)
  • del - remove from a list by position
  • try, except - handle an exception, basic use (2 keywords)
  • raise, assert - raise/indicate an exception (2 keywords)
  • in - test if something is inside of a list/string/tuple/dictionary
  • None - special value for a variable that has no value
  • pass - empty statement that does not do anything

More Keywords

These keywords are often not introduced or heavily used until the second Python course.

  • as, finally, with, else - exception handling, more keywords (4 keywords)
  • class - defining new class data type (for object-oriented programming)
  • lambda - create unnamed / anonymous function
  • global, nonlocal - access variables outside of current scope (2 keywords)
  • async, await - for writing asynchronous code with asynchio package (2 keywords)
  • yield - for creating generator functions

Concepts

See this video for a demo and explanation of basic data types and variables.

These are terms that we use to describe programs. These are terms that have a precise meaning when talking about programs.

  • string - text data type
  • boolean - data type for True and False
  • floating point - data type that stores numbers with fractional parts (e.g., 3.14 or 2.2)
  • integer - data type that stores only integers
  • None - a special value in Python that means "nothing" but is different than 0, False, and ""
  • variable - name for a place in memory to store values. Two basic things you do with a variable - (i) store a value into the variable, (ii) get the value from the variable.
  • keywords - also called reserved words - these are names that should not be used for variable names because they have special meaning to python. Example: for is used for loops and shouldn't be used as a variable name.
  • function - also called procedures or methods - name for a block of code that does something and that your code can use when needed. Two basic things you can do with a function - (i) define what the function is (specify the code for the function), (ii) call the function later on in your code. Three main parts of defining function - (a) function code (called the body), (b) function parameters (aka input variables), (c) function return values. Three main parts of calling/using a function - (1) specify the arguments to the function (which are passed in to the parameters of the function), (2) call the function, (3) get the return value of the function. Note that the function prototype refers to the line that declares the function, which has the function name, return type, and list of parameters to the function. When a function is called, the arguments to the function are passed to the function (parameter variables are set equal to the arguments).
  • flow chart - diagram that shows the steps / flow of control in a program (also used to diagram decision-making in other settings - e.g., diagnosis of an illness, managing a factory, ...)
  • binary operator - operator that takes two values to produce a result. An example is addition, 2 + 3 results in 5. Another example is == comparison, 'hi' == 'bye' results in False because the two are not equal.
  • unary operator - operator that takes one value to produce a result. An example is Boolean not, not True results in False.
  • operator precedence - rules for which operators are evaluated first in an expression. For example, in 1 + 2 * 3, the multiplication is performed first, giving 1 + 6, and then the + is performed to result in 7. For Python, see python.org.
  • operator associativity - rule whether operators of the same type are evaluated left-to-right or right-to-left. Math operators are left-to-right. For Python, see python.org.

More Information

Python built-in types - includes information on operations that come along with the builtin types.

Commonly Used Functions

  • print - function to write to the screen
  • int, float, str - functions to convert to integer, floating point number, or string
  • range - function to generate a sequence of numbers
  • len - function to get the length of a string, list, or tuple
  • open, read, write, close - functions for reading/writing text files and options 'r', 'w', 'a' for open
  • string methods - isalpha, isdigit, split, join
  • list methods - sort, index, append, remove, copy
  • tuple methods - index, count
  • dictionary methods - keys, values, items
  • syntax for using strings, lists, tuples dictionaries -
  • methods in random module - randint, shuffle
  • methods in sys module - exit, argv list
  • methods from the copy module - copy.deepcopy

Assignment

It is traditional to have a quiz where you must properly be able to identify all Python keywords and data types. A quiz that you can practice with is - Python Keywords and Data Types Quiz.

Pass rating check If you are assigned this quiz in a course, you should be able to get 100% once you get comfortable with Python.