- Get started in your class team
- Get organized in your class team
- Meetings, chats, and posts
- Share and organize class team files
Assignments and grades in your class team
- Use Class Notebook in Teams
- Downloadable guides
- Training for teachers
- Plan a training - we'll help!
- Get the overview
- Use Class Notebook and Teams together
- Choose a background and class view
- Manage student participation
- Set up meeting roles and safety
- Present and share content
- Schedule and join a meeting
- Set up your class view
- Tips for an inclusive class meeting
- Use the toolbar
- Educator's guide to Insights in Microsoft Teams
- All-classes view in the Insights app
- Class overview page in Insights
- Assignments and grades in Insights
- Digital activity data in Insights
- View Reflect data in Insights
- View Reading Progress data in Insights
- Use Insights to create Reading Progress challenge assignments
- Student support cards in Insights
- Student transparency in Insights
- About Education Insights Premium
- Navigate your dashboard
- Digital engagement data
- Workload data
- Reading Progress data
- Export your data
Create, submit, and grade assignments, all in Microsoft Teams .
Create an assignment
Navigate to your class team and select Assignments .
Select Create > Assignment .
Add details to your assignment
The only thing your assignment requires to be saved is a title. All other fields are optional.
Choose multiple classes or individual students in one class to assign to.
Add additional instructions
Add resources. (See below.)
Select a due date and time. (See below.)
Add a grading rubric .
Add a category .
Tip: Read more step-by-step instructions for reusing assignments, assigning quizzes, and more.
When you are finished, select Assign. To save this assignment as a draft, select Save.
More on adding resources
Select Add resources to choose an existing file or create a blank Office 365 document to assign to each student.
Select Attach .
The default for the file will be Students can't edit , which means the document is read-only. This is a great option for reference materials.
Choose assignment timeline
To set a future assign date or prevent students from turning in late assignments, select Edit underneath the due date field.
Make your selections and select Done .
Note: By default, close dates are not selected, allowing students to turn assignments in assignments.
Track student progress and access grades in Grades.
Navigate to your class team and select Grades .
Assignments appear in rows and your students in a column. Assignments are in listed in order by soonest due date. Scroll down or across to view all assignments.
You can also view students' assignment statuses:
Viewed - The student has opened and viewed the assignment.
Turned in - The student has turned in the assignment and work is ready to grade.
Returned or points - When you've graded student work, the points assigned will show. You'll see Returned if the assignment doesn't have points.
Blank - No action has been taken on the assignment yet.
You can select any cell in the Grades tab to edit it.
This will open your student's assignment with a Feedback and Points field you can fill in.
To write comments on the document itself, select Edit Document and either choose to edit in your desktop app or browser.
Select the arrows next to the student's name to navigate between student assignments.
Select Return > Return or Return for revision when you finish grading and want to return an assignment to a student. They will be notified and able to see your feedback.
Return multiple grades at once
To return multiple student grades simultaneously, select Assignments .
Select an assignment.
You can enter feedback and points here without opening student work.
Check the boxes to specify which student work to return, or select all.
Click Return > Return or Return for revision .
Tip: Learn more about the Grades tab and reviewing student work .
View and turn in assignments
Navigate to a class team and select Assignments .
To view assignment details and submit your work, select the assignment.
Attach any required materials and select Turn in .
See your grades
To view grades for assignments your educator has reviewed and sent back to you:
Select Grades in your class team.
All your assignments are listed here with the nearest due date at the top. View your status on each assignment as well as points you've received on graded work. Assignments without points will show as Returned after your educator has reviewed them.
Use the arrows next to Due date and Assignment to sort your assignments.
Need more help?
Want more options.
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
Microsoft 365 subscription benefits
Microsoft 365 training
Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.
Ask the Microsoft Community
Microsoft Tech Community
Microsoft 365 Insiders
Was this information helpful?
Thank you for your feedback.
- Skill Assessments
- AI Course Builder
- Free Courses
- Google Classroom: Teachers
Grade, Return, and Delete Assignments
Start Free Trial
Or log in with:
How to Grade, Return, and Delete Assignments in Google Classroom
After you create assignments, they show up for students on the Classwork page. It's their responsibility to complete and turn them in by the due date. You can check the progress of an assignment on the Classwork page by clicking the assignment. This gives you an at-a-glance view of how many students have turned it in and how many additional students it's assigned to. When it’s time to review and grade assignments, you’ll do that from the Grades page.
Grade and Return Assignments
Here you see a table with each assignment listed at the top and separate cells to add a grade for every student in the class. If the assignment is past the due date, it displays as Missing for any students who didn't turn it in.
- Click the More button in the cell where you want to enter a grade.
The completed assignment opens in a new browser tab. You can add a comment to the file using the icon on the left side of the Files pane. Or, view the file in a new browser tab without any of the grading options by clicking the icon to the right of the file name in the Files pane.
- Add a grade for the assignment.
- (Optional) Add a comment and click Post .
The dialog box notifies you that the student will now be able to view their grade.
Once the assignment is graded, you can close the tab with the assignment to return to the gradebook.
If an assignment is no longer needed, simply delete it. Deleting an assignment removes it, along with any associated grades or comments, from Classroom. However, any files or attachments created in Google Drive will still remain. You’ll need to manually delete those in Drive if you don’t want to retain copies.
Be aware that deleting an assignment is permanent. There is no way to undo the deletion.
- On the Grades page, click the More button for an assignment.
The dialog box notifies you that any grades and comments associated with the assignment will also be deleted.
FREE Quick Reference
Free to distribute with our compliments; we hope you will consider our paid training.
- LinkedIn-ready certificate
- Skill assessments
- Bite-sized, interactive lessons
- Saved progress
404 Not found
- Python »
- 3.12.1 Documentation »
- The Python Tutorial »
- Theme Auto Light Dark |
9. Classes ¶
Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state.
Compared with other programming languages, Python’s class mechanism adds classes with a minimum of new syntax and semantics. It is a mixture of the class mechanisms found in C++ and Modula-3. Python classes provide all the standard features of Object Oriented Programming: the class inheritance mechanism allows multiple base classes, a derived class can override any methods of its base class or classes, and a method can call the method of a base class with the same name. Objects can contain arbitrary amounts and kinds of data. As is true for modules, classes partake of the dynamic nature of Python: they are created at runtime, and can be modified further after creation.
In C++ terminology, normally class members (including the data members) are public (except see below Private Variables ), and all member functions are virtual . As in Modula-3, there are no shorthands for referencing the object’s members from its methods: the method function is declared with an explicit first argument representing the object, which is provided implicitly by the call. As in Smalltalk, classes themselves are objects. This provides semantics for importing and renaming. Unlike C++ and Modula-3, built-in types can be used as base classes for extension by the user. Also, like in C++, most built-in operators with special syntax (arithmetic operators, subscripting etc.) can be redefined for class instances.
(Lacking universally accepted terminology to talk about classes, I will make occasional use of Smalltalk and C++ terms. I would use Modula-3 terms, since its object-oriented semantics are closer to those of Python than C++, but I expect that few readers have heard of it.)
9.1. A Word About Names and Objects ¶
Objects have individuality, and multiple names (in multiple scopes) can be bound to the same object. This is known as aliasing in other languages. This is usually not appreciated on a first glance at Python, and can be safely ignored when dealing with immutable basic types (numbers, strings, tuples). However, aliasing has a possibly surprising effect on the semantics of Python code involving mutable objects such as lists, dictionaries, and most other types. This is usually used to the benefit of the program, since aliases behave like pointers in some respects. For example, passing an object is cheap since only a pointer is passed by the implementation; and if a function modifies an object passed as an argument, the caller will see the change — this eliminates the need for two different argument passing mechanisms as in Pascal.
9.2. Python Scopes and Namespaces ¶
Before introducing classes, I first have to tell you something about Python’s scope rules. Class definitions play some neat tricks with namespaces, and you need to know how scopes and namespaces work to fully understand what’s going on. Incidentally, knowledge about this subject is useful for any advanced Python programmer.
Let’s begin with some definitions.
A namespace is a mapping from names to objects. Most namespaces are currently implemented as Python dictionaries, but that’s normally not noticeable in any way (except for performance), and it may change in the future. Examples of namespaces are: the set of built-in names (containing functions such as abs() , and built-in exception names); the global names in a module; and the local names in a function invocation. In a sense the set of attributes of an object also form a namespace. The important thing to know about namespaces is that there is absolutely no relation between names in different namespaces; for instance, two different modules may both define a function maximize without confusion — users of the modules must prefix it with the module name.
By the way, I use the word attribute for any name following a dot — for example, in the expression z.real , real is an attribute of the object z . Strictly speaking, references to names in modules are attribute references: in the expression modname.funcname , modname is a module object and funcname is an attribute of it. In this case there happens to be a straightforward mapping between the module’s attributes and the global names defined in the module: they share the same namespace! 1
Attributes may be read-only or writable. In the latter case, assignment to attributes is possible. Module attributes are writable: you can write modname.the_answer = 42 . Writable attributes may also be deleted with the del statement. For example, del modname.the_answer will remove the attribute the_answer from the object named by modname .
Namespaces are created at different moments and have different lifetimes. The namespace containing the built-in names is created when the Python interpreter starts up, and is never deleted. The global namespace for a module is created when the module definition is read in; normally, module namespaces also last until the interpreter quits. The statements executed by the top-level invocation of the interpreter, either read from a script file or interactively, are considered part of a module called __main__ , so they have their own global namespace. (The built-in names actually also live in a module; this is called builtins .)
The local namespace for a function is created when the function is called, and deleted when the function returns or raises an exception that is not handled within the function. (Actually, forgetting would be a better way to describe what actually happens.) Of course, recursive invocations each have their own local namespace.
A scope is a textual region of a Python program where a namespace is directly accessible. “Directly accessible” here means that an unqualified reference to a name attempts to find the name in the namespace.
Although scopes are determined statically, they are used dynamically. At any time during execution, there are 3 or 4 nested scopes whose namespaces are directly accessible:
the innermost scope, which is searched first, contains the local names
the scopes of any enclosing functions, which are searched starting with the nearest enclosing scope, contain non-local, but also non-global names
the next-to-last scope contains the current module’s global names
the outermost scope (searched last) is the namespace containing built-in names
If a name is declared global, then all references and assignments go directly to the next-to-last scope containing the module’s global names. To rebind variables found outside of the innermost scope, the nonlocal statement can be used; if not declared nonlocal, those variables are read-only (an attempt to write to such a variable will simply create a new local variable in the innermost scope, leaving the identically named outer variable unchanged).
Usually, the local scope references the local names of the (textually) current function. Outside functions, the local scope references the same namespace as the global scope: the module’s namespace. Class definitions place yet another namespace in the local scope.
It is important to realize that scopes are determined textually: the global scope of a function defined in a module is that module’s namespace, no matter from where or by what alias the function is called. On the other hand, the actual search for names is done dynamically, at run time — however, the language definition is evolving towards static name resolution, at “compile” time, so don’t rely on dynamic name resolution! (In fact, local variables are already determined statically.)
A special quirk of Python is that – if no global or nonlocal statement is in effect – assignments to names always go into the innermost scope. Assignments do not copy data — they just bind names to objects. The same is true for deletions: the statement del x removes the binding of x from the namespace referenced by the local scope. In fact, all operations that introduce new names use the local scope: in particular, import statements and function definitions bind the module or function name in the local scope.
The global statement can be used to indicate that particular variables live in the global scope and should be rebound there; the nonlocal statement indicates that particular variables live in an enclosing scope and should be rebound there.
9.2.1. Scopes and Namespaces Example ¶
This is an example demonstrating how to reference the different scopes and namespaces, and how global and nonlocal affect variable binding:
The output of the example code is:
Note how the local assignment (which is default) didn’t change scope_test 's binding of spam . The nonlocal assignment changed scope_test 's binding of spam , and the global assignment changed the module-level binding.
You can also see that there was no previous binding for spam before the global assignment.
9.3. A First Look at Classes ¶
Classes introduce a little bit of new syntax, three new object types, and some new semantics.
9.3.1. Class Definition Syntax ¶
The simplest form of class definition looks like this:
Class definitions, like function definitions ( def statements) must be executed before they have any effect. (You could conceivably place a class definition in a branch of an if statement, or inside a function.)
In practice, the statements inside a class definition will usually be function definitions, but other statements are allowed, and sometimes useful — we’ll come back to this later. The function definitions inside a class normally have a peculiar form of argument list, dictated by the calling conventions for methods — again, this is explained later.
When a class definition is entered, a new namespace is created, and used as the local scope — thus, all assignments to local variables go into this new namespace. In particular, function definitions bind the name of the new function here.
When a class definition is left normally (via the end), a class object is created. This is basically a wrapper around the contents of the namespace created by the class definition; we’ll learn more about class objects in the next section. The original local scope (the one in effect just before the class definition was entered) is reinstated, and the class object is bound here to the class name given in the class definition header ( ClassName in the example).
9.3.2. Class Objects ¶
Class objects support two kinds of operations: attribute references and instantiation.
Attribute references use the standard syntax used for all attribute references in Python: obj.name . Valid attribute names are all the names that were in the class’s namespace when the class object was created. So, if the class definition looked like this:
then MyClass.i and MyClass.f are valid attribute references, returning an integer and a function object, respectively. Class attributes can also be assigned to, so you can change the value of MyClass.i by assignment. __doc__ is also a valid attribute, returning the docstring belonging to the class: "A simple example class" .
Class instantiation uses function notation. Just pretend that the class object is a parameterless function that returns a new instance of the class. For example (assuming the above class):
creates a new instance of the class and assigns this object to the local variable x .
The instantiation operation (“calling” a class object) creates an empty object. Many classes like to create objects with instances customized to a specific initial state. Therefore a class may define a special method named __init__() , like this:
When a class defines an __init__() method, class instantiation automatically invokes __init__() for the newly created class instance. So in this example, a new, initialized instance can be obtained by:
Of course, the __init__() method may have arguments for greater flexibility. In that case, arguments given to the class instantiation operator are passed on to __init__() . For example,
9.3.3. Instance Objects ¶
Now what can we do with instance objects? The only operations understood by instance objects are attribute references. There are two kinds of valid attribute names: data attributes and methods.
data attributes correspond to “instance variables” in Smalltalk, and to “data members” in C++. Data attributes need not be declared; like local variables, they spring into existence when they are first assigned to. For example, if x is the instance of MyClass created above, the following piece of code will print the value 16 , without leaving a trace:
The other kind of instance attribute reference is a method . A method is a function that “belongs to” an object. (In Python, the term method is not unique to class instances: other object types can have methods as well. For example, list objects have methods called append, insert, remove, sort, and so on. However, in the following discussion, we’ll use the term method exclusively to mean methods of class instance objects, unless explicitly stated otherwise.)
Valid method names of an instance object depend on its class. By definition, all attributes of a class that are function objects define corresponding methods of its instances. So in our example, x.f is a valid method reference, since MyClass.f is a function, but x.i is not, since MyClass.i is not. But x.f is not the same thing as MyClass.f — it is a method object , not a function object.
9.3.4. Method Objects ¶
Usually, a method is called right after it is bound:
In the MyClass example, this will return the string 'hello world' . However, it is not necessary to call a method right away: x.f is a method object, and can be stored away and called at a later time. For example:
will continue to print hello world until the end of time.
What exactly happens when a method is called? You may have noticed that x.f() was called without an argument above, even though the function definition for f() specified an argument. What happened to the argument? Surely Python raises an exception when a function that requires an argument is called without any — even if the argument isn’t actually used…
Actually, you may have guessed the answer: the special thing about methods is that the instance object is passed as the first argument of the function. In our example, the call x.f() is exactly equivalent to MyClass.f(x) . In general, calling a method with a list of n arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method’s instance object before the first argument.
If you still don’t understand how methods work, a look at the implementation can perhaps clarify matters. When a non-data attribute of an instance is referenced, the instance’s class is searched. If the name denotes a valid class attribute that is a function object, a method object is created by packing (pointers to) the instance object and the function object just found together in an abstract object: this is the method object. When the method object is called with an argument list, a new argument list is constructed from the instance object and the argument list, and the function object is called with this new argument list.
9.3.5. Class and Instance Variables ¶
Generally speaking, instance variables are for data unique to each instance and class variables are for attributes and methods shared by all instances of the class:
As discussed in A Word About Names and Objects , shared data can have possibly surprising effects with involving mutable objects such as lists and dictionaries. For example, the tricks list in the following code should not be used as a class variable because just a single list would be shared by all Dog instances:
Correct design of the class should use an instance variable instead:
9.4. Random Remarks ¶
If the same attribute name occurs in both an instance and in a class, then attribute lookup prioritizes the instance:
Data attributes may be referenced by methods as well as by ordinary users (“clients”) of an object. In other words, classes are not usable to implement pure abstract data types. In fact, nothing in Python makes it possible to enforce data hiding — it is all based upon convention. (On the other hand, the Python implementation, written in C, can completely hide implementation details and control access to an object if necessary; this can be used by extensions to Python written in C.)
Clients should use data attributes with care — clients may mess up invariants maintained by the methods by stamping on their data attributes. Note that clients may add data attributes of their own to an instance object without affecting the validity of the methods, as long as name conflicts are avoided — again, a naming convention can save a lot of headaches here.
There is no shorthand for referencing data attributes (or other methods!) from within methods. I find that this actually increases the readability of methods: there is no chance of confusing local variables and instance variables when glancing through a method.
Often, the first argument of a method is called self . This is nothing more than a convention: the name self has absolutely no special meaning to Python. Note, however, that by not following the convention your code may be less readable to other Python programmers, and it is also conceivable that a class browser program might be written that relies upon such a convention.
Any function object that is a class attribute defines a method for instances of that class. It is not necessary that the function definition is textually enclosed in the class definition: assigning a function object to a local variable in the class is also ok. For example:
Now f , g and h are all attributes of class C that refer to function objects, and consequently they are all methods of instances of C — h being exactly equivalent to g . Note that this practice usually only serves to confuse the reader of a program.
Methods may call other methods by using method attributes of the self argument:
Methods may reference global names in the same way as ordinary functions. The global scope associated with a method is the module containing its definition. (A class is never used as a global scope.) While one rarely encounters a good reason for using global data in a method, there are many legitimate uses of the global scope: for one thing, functions and modules imported into the global scope can be used by methods, as well as functions and classes defined in it. Usually, the class containing the method is itself defined in this global scope, and in the next section we’ll find some good reasons why a method would want to reference its own class.
Each value is an object, and therefore has a class (also called its type ). It is stored as object.__class__ .
9.5. Inheritance ¶
Of course, a language feature would not be worthy of the name “class” without supporting inheritance. The syntax for a derived class definition looks like this:
The name BaseClassName must be defined in a namespace accessible from the scope containing the derived class definition. In place of a base class name, other arbitrary expressions are also allowed. This can be useful, for example, when the base class is defined in another module:
Execution of a derived class definition proceeds the same as for a base class. When the class object is constructed, the base class is remembered. This is used for resolving attribute references: if a requested attribute is not found in the class, the search proceeds to look in the base class. This rule is applied recursively if the base class itself is derived from some other class.
There’s nothing special about instantiation of derived classes: DerivedClassName() creates a new instance of the class. Method references are resolved as follows: the corresponding class attribute is searched, descending down the chain of base classes if necessary, and the method reference is valid if this yields a function object.
Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class may end up calling a method of a derived class that overrides it. (For C++ programmers: all methods in Python are effectively virtual .)
An overriding method in a derived class may in fact want to extend rather than simply replace the base class method of the same name. There is a simple way to call the base class method directly: just call BaseClassName.methodname(self, arguments) . This is occasionally useful to clients as well. (Note that this only works if the base class is accessible as BaseClassName in the global scope.)
Python has two built-in functions that work with inheritance:
Use isinstance() to check an instance’s type: isinstance(obj, int) will be True only if obj.__class__ is int or some class derived from int .
Use issubclass() to check class inheritance: issubclass(bool, int) is True since bool is a subclass of int . However, issubclass(float, int) is False since float is not a subclass of int .
9.5.1. Multiple Inheritance ¶
Python supports a form of multiple inheritance as well. A class definition with multiple base classes looks like this:
For most purposes, in the simplest cases, you can think of the search for attributes inherited from a parent class as depth-first, left-to-right, not searching twice in the same class where there is an overlap in the hierarchy. Thus, if an attribute is not found in DerivedClassName , it is searched for in Base1 , then (recursively) in the base classes of Base1 , and if it was not found there, it was searched for in Base2 , and so on.
In fact, it is slightly more complex than that; the method resolution order changes dynamically to support cooperative calls to super() . This approach is known in some other multiple-inheritance languages as call-next-method and is more powerful than the super call found in single-inheritance languages.
Dynamic ordering is necessary because all cases of multiple inheritance exhibit one or more diamond relationships (where at least one of the parent classes can be accessed through multiple paths from the bottommost class). For example, all classes inherit from object , so any case of multiple inheritance provides more than one path to reach object . To keep the base classes from being accessed more than once, the dynamic algorithm linearizes the search order in a way that preserves the left-to-right ordering specified in each class, that calls each parent only once, and that is monotonic (meaning that a class can be subclassed without affecting the precedence order of its parents). Taken together, these properties make it possible to design reliable and extensible classes with multiple inheritance. For more detail, see https://www.python.org/download/releases/2.3/mro/ .
9.6. Private Variables ¶
“Private” instance variables that cannot be accessed except from inside an object don’t exist in Python. However, there is a convention that is followed by most Python code: a name prefixed with an underscore (e.g. _spam ) should be treated as a non-public part of the API (whether it is a function, a method or a data member). It should be considered an implementation detail and subject to change without notice.
Since there is a valid use-case for class-private members (namely to avoid name clashes of names with names defined by subclasses), there is limited support for such a mechanism, called name mangling . Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam , where classname is the current class name with leading underscore(s) stripped. This mangling is done without regard to the syntactic position of the identifier, as long as it occurs within the definition of a class.
Name mangling is helpful for letting subclasses override methods without breaking intraclass method calls. For example:
The above example would work even if MappingSubclass were to introduce a __update identifier since it is replaced with _Mapping__update in the Mapping class and _MappingSubclass__update in the MappingSubclass class respectively.
Note that the mangling rules are designed mostly to avoid accidents; it still is possible to access or modify a variable that is considered private. This can even be useful in special circumstances, such as in the debugger.
Notice that code passed to exec() or eval() does not consider the classname of the invoking class to be the current class; this is similar to the effect of the global statement, the effect of which is likewise restricted to code that is byte-compiled together. The same restriction applies to getattr() , setattr() and delattr() , as well as when referencing __dict__ directly.
9.7. Odds and Ends ¶
Sometimes it is useful to have a data type similar to the Pascal “record” or C “struct”, bundling together a few named data items. The idiomatic approach is to use dataclasses for this purpose:
A piece of Python code that expects a particular abstract data type can often be passed a class that emulates the methods of that data type instead. For instance, if you have a function that formats some data from a file object, you can define a class with methods read() and readline() that get the data from a string buffer instead, and pass it as an argument.
Instance method objects have attributes, too: m.__self__ is the instance object with the method m() , and m.__func__ is the function object corresponding to the method.
9.8. Iterators ¶
By now you have probably noticed that most container objects can be looped over using a for statement:
This style of access is clear, concise, and convenient. The use of iterators pervades and unifies Python. Behind the scenes, the for statement calls iter() on the container object. The function returns an iterator object that defines the method __next__() which accesses elements in the container one at a time. When there are no more elements, __next__() raises a StopIteration exception which tells the for loop to terminate. You can call the __next__() method using the next() built-in function; this example shows how it all works:
Having seen the mechanics behind the iterator protocol, it is easy to add iterator behavior to your classes. Define an __iter__() method which returns an object with a __next__() method. If the class defines __next__() , then __iter__() can just return self :
9.9. Generators ¶
Generators are a simple and powerful tool for creating iterators. They are written like regular functions but use the yield statement whenever they want to return data. Each time next() is called on it, the generator resumes where it left off (it remembers all the data values and which statement was last executed). An example shows that generators can be trivially easy to create:
Anything that can be done with generators can also be done with class-based iterators as described in the previous section. What makes generators so compact is that the __iter__() and __next__() methods are created automatically.
Another key feature is that the local variables and execution state are automatically saved between calls. This made the function easier to write and much more clear than an approach using instance variables like self.index and self.data .
In addition to automatic method creation and saving program state, when generators terminate, they automatically raise StopIteration . In combination, these features make it easy to create iterators with no more effort than writing a regular function.
9.10. Generator Expressions ¶
Some simple generators can be coded succinctly as expressions using a syntax similar to list comprehensions but with parentheses instead of square brackets. These expressions are designed for situations where the generator is used right away by an enclosing function. Generator expressions are more compact but less versatile than full generator definitions and tend to be more memory friendly than equivalent list comprehensions.
Except for one thing. Module objects have a secret read-only attribute called __dict__ which returns the dictionary used to implement the module’s namespace; the name __dict__ is an attribute but not a global name. Obviously, using this violates the abstraction of namespace implementation, and should be restricted to things like post-mortem debuggers.
Table of Contents
- 9.1. A Word About Names and Objects
- 9.2.1. Scopes and Namespaces Example
- 9.3.1. Class Definition Syntax
- 9.3.2. Class Objects
- 9.3.3. Instance Objects
- 9.3.4. Method Objects
- 9.3.5. Class and Instance Variables
- 9.4. Random Remarks
- 9.5.1. Multiple Inheritance
- 9.6. Private Variables
- 9.7. Odds and Ends
- 9.8. Iterators
- 9.9. Generators
- 9.10. Generator Expressions
8. Errors and Exceptions
10. Brief Tour of the Standard Library
- Report a Bug
- Show Source
Assignment operators modify the value of the object.
[ edit ] Explanation
copy assignment operator replaces the contents of the object a with a copy of the contents of b ( b is not modified). For class types, this is a special member function, described in copy assignment operator .
For non-class types, copy and move assignment are indistinguishable and are referred to as direct assignment .
compound assignment operators replace the contents of the object a with the result of a binary operation between the previous value of a and the value of b .
[ edit ] Builtin direct assignment
The direct assignment expressions have the form
For the built-in operator, lhs may have any non-const scalar type and rhs must be implicitly convertible to the type of lhs .
The direct assignment operator expects a modifiable lvalue as its left operand and an rvalue expression or a braced-init-list (since C++11) as its right operand, and returns an lvalue identifying the left operand after modification. The result is a bit-field if the left operand is a bit-field.
For non-class types, the right operand is first implicitly converted to the cv-unqualified type of the left operand, and then its value is copied into the object identified by left operand.
When the left operand has reference type, the assignment operator modifies the referred-to object.
If the left and the right operands identify overlapping objects, the behavior is undefined (unless the overlap is exact and the type is the same).
In overload resolution against user-defined operators , for every type T , the following function signatures participate in overload resolution:
For every enumeration or pointer to member type T , optionally volatile-qualified, the following function signature participates in overload resolution:
For every pair A1 and A2, where A1 is an arithmetic type (optionally volatile-qualified) and A2 is a promoted arithmetic type, the following function signature participates in overload resolution:
[ edit ] Example
[ edit ] Builtin compound assignment
The compound assignment expressions have the form
The behavior of every builtin compound-assignment expression E1 op = E2 (where E1 is a modifiable lvalue expression and E2 is an rvalue expression or a braced-init-list (since C++11) ) is exactly the same as the behavior of the expression E1 = E1 op E2 , except that the expression E1 is evaluated only once and that it behaves as a single operation with respect to indeterminately-sequenced function calls (e.g. in f ( a + = b, g ( ) ) , the += is either not started at all or is completed as seen from inside g ( ) ).
In overload resolution against user-defined operators , for every pair A1 and A2, where A1 is an arithmetic type (optionally volatile-qualified) and A2 is a promoted arithmetic type, the following function signatures participate in overload resolution:
For every pair I1 and I2, where I1 is an integral type (optionally volatile-qualified) and I2 is a promoted integral type, the following function signatures participate in overload resolution:
For every optionally cv-qualified object type T , the following function signatures participate in overload resolution:
[ edit ] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
[ edit ] See also
- Todo no example
- Recent changes
- Offline version
- What links here
- Related changes
- Upload file
- Special pages
- Printable version
- Permanent link
- Page information
- In other languages
- This page was last modified on 9 July 2023, at 05:09.
- This page has been accessed 405,963 times.
- About cppreference.com
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
- 5 contributors
Make the grade and feedback associated with this submission available to the student.
This action changes the status of the submission from "submitted" to "returned" and indicates that feedback is provided or grading is done. This action can only be done by the teacher.
This API is available in the following national cloud deployments .
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it . For details about delegated and application permissions, see Permission types . To learn more about these permissions, see the permissions reference .
Request headers, request body.
Don't supply a request body for this method.
If successful, this method returns a 200 Ok response code and an educationSubmission object in the response body.
The following example shows how to call this API.
The following example shows a request.
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
The following example shows the response.
- States, transitions, and limitations for assignments and submissions
Submit and view feedback for
Written by Chris Gregg, Julie Zelenski and others, with modifications by Nick Troccoli and Lisa Yan
Click here for a walkthrough video.
All Macs have a built-in Terminal program, since like Myth machines they are also built on top of Unix. You can find the Terminal program by searching for it via the magnifying-glass in the top-right corner of your desktop, or by opening the Applications folder and going into Utilities .
When you open Terminal, initially you'll be seeing the files and programs of your own computer , just through the lens of Terminal instead of Finder.
We'll need to configure one setting (a one-time change) before logging in to myth: in the top menu bar, click Terminal -> Preferences -> Profiles -> Keyboard -> "Use Option as Meta Key". This means the "Option" key on your keyboard will act as the "Meta" key for Emacs, instead of the Escape key. You'll learn more about Emacs later.
Note - when you open terminal for the first time, you may see the following message:
The default interactive shell is now zsh. To update your account to use zsh, please run chsh -s /bin/zsh . For more details, please visit https://support.apple.com/kb/HT208050.
This is asking whether you'd like to update the version of your shell on your Mac. Either way, this will not impact anything about logging into myth - but you can update if you'd like by running the specified command.
Now that you're all configured, use the ssh command to connect to the myth machines. Just be sure to keep track in your own mind of whether you're on myth or your own computer at any given moment! The command you want to type is:
where sunet is your SUNet ID (i.e., the name part of your stanford email address, so if your SUNet ID is troccoli, you would type ssh [email protected] ). It will ask for your password, which is your usual Stanford password. If it asks you to confirm that you would like to access myth , type "yes". And now you're logged into myth!
Windows 10 and 11 have a Terminal program that you can use to log into the Myth machines. You can find the Terminal program by searching for it via the start menu at the bottom-center of your screen, or by downloading it from the Microsoft Store .
Now, open Terminal and use the ssh command to connect to the myth machines. The command you want to type is:
Older Windows Versions
Older Windows versions (prior to April 2018) do not have a Windows PowerShell program that supports ssh functionality, but there is a program called PuTTY that provides ssh functionality instead.
Putty is available here - download the package file, or scroll down to the "Alternative Binary Files" section for files that don't need to be installed (for example, if it is not your computer and you don't have permission to install software). Use the 64-bit version (or 32-bit if your computer is more than about 5 years old).
Here's how to use it to connect to Myth:
- In the Host Name field, type "myth.stanford.edu".
- Leave everything else as-is, and click "Open" at the bottom of the window to connect.
- If a security alert appears about a host key, click "Yes".
- When the program prompts you with "login as:", enter your SUNET ID (e.g. part before @stanford.edu).
- When the program prompts you with "password", enter your Stanford password.
Note that SecureCRT is not as compatible with Emacs mouse commands as the above two options.
Download and install the SecureCRT software program that will run ssh for you. It is available as a free download from Stanford . Of the two download options at that link (32-bit and 64-bit), choose 64-bit unless your computer is more than about 5 years old.
After the program is installed, launch it.
We'll need to configure some Emacs settings (a one-time change) before logging in to myth.
- In the top menu bar, click Options->Edit Default Session
- Select "Emacs" as the category, under Terminal->Emulation
- Check the box "Use ALT as meta key". This means the "Alt" key on your keyboard will act as the "Meta" key for Emacs, instead of being used to access shortcuts within SecureCRT. Take a look at our Emacs guide for more information about Emacs.
- Click OK to save the changes.
- When it asks you whether you would like to apply this to all sessions, select that you'd just like to change the Default Session.
A general setting to configure:
- In the top menu bar, click Options->Edit Default Session
- On the "Terminal/Emulation" page, set the emulation to "Xterm"
- Make sure the value of the "Terminal type" option in the "Terminal / Emulation / Advanced" category is NOT enabled.
- If it asks you whether you would like to apply this to all sessions, select that you'd just like to change the Default Session.
Now we can connect to Myth:
- Go to File -> Quick Connect.
- Enter Hostname "myth.stanford.edu".
- For Username, enter your SUNet ID (i.e., the name part of your stanford email address).
- Leave everything else as-is, and click Connect.
- If it asks you about a New Host Key, click "Accept & Save".
- At the password prompt, enter your Stanford password.
Now you should be logged into Myth! Note that you didn't need to actually type the ssh command, as the program is your ssh client and did this for you. Also, you'll only need to do the above steps once; when you launch SecureCRT in the future, myth will now be listed underneath the available Sessions in the program sidebar for you to double-click on. (If you don't see this sidebar, click the toolbar icon in the top-left corner of the window that looks like a file tree).
All Linux machines have a built-in Terminal program, since like Myth machines they are also built on top of Unix. You can find the Terminal program by searching for it using the search functionality of your chosen Linux version. For instance, Ubuntu users can follow the instructions in this WikiHow guide .
When you open Terminal, initially you'll be seeing the files and programs of your own computer , just through the lens of Terminal instead of your graphical filesystem. From there, use the ssh command to connect to the myth machines. Just be sure to keep track in your own mind of whether you're on myth or your own computer at any given moment! The command you want to type is:
My windows 10 computer is in a different language without alphanumerical characters, such as chinese, and i'm having trouble with the instructions..
Ubuntu (the software that is installed in the instructions) may not be able to recognize your user folder name to properly install. If possible, one solution is to change your computer's display language to English, which entails making a new admin account, unsyncing the language, and changing the display language, such that everything is in English. However, this might not be possible in the Home Edition of Windows 10. If for this or other reasons you are not able to or would not like to change the language, we advise that you instead follow the instructions on this page to install the SecureCRT program. [Thanks to TA Annie S.]
- For more information about SUNET IDs, click here
- For more information about AFS, click here
- For more information about the myth cluster, click here . You will need to be a declared CS student to access this page, as the myth cluster is managed by the CS department and intended for general use by CS department students.
- For more information about the Stanford Farmshare environment, the larger group of systems you can access (and of which myth is a subgroup), click here .
- Optionally, you can configure Xwindows to enable graphical windows.
- Skip to main content
- Skip to FDA Search
- Skip to in this section menu
- Skip to footer links
The .gov means it’s official. Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you're on a federal government site.
The site is secure. The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.
U.S. Food and Drug Administration
- Medical Devices
- Medical Device Safety
- Medical Device Recalls
ResMed Ltd. Recalls Continuous Positive Airway Pressure (CPAP) Masks with Magnets due to Possible Magnetic Interference with Certain Medical Devices
The FDA has identified this as a Class I recall, the most serious type of recall. Use of these devices may cause serious injuries or death.
Please be aware, this recall is a correction, not a product removal.
- Product Names: AirFit and AirTouch masks
- Class 1 Device Recall AirFit N10 (fda.gov)
- Class 1 Device Recall AirFit F20 (fda.gov)
- Class 1 Device Recall AirTouch F20 (fda.gov)
- Class 1 Device Recall AirFit N20 (fda.gov)
- Class 1 Device Recall AirTouch N20 (fda.gov)
- Class 1 Device Recall AirFit F30 (fda.gov)
- Class 1 Device Recall AirFit F30i (fda.gov)
- Model Numbers: AirFit N10, AirFit F20, AirTouch F20, AirFit N20, AirTouch N20, AirFit F30, AirFit F30i
- Distribution Dates: January 2020 to November 20, 2023
- Devices Recalled in the U.S.: 20,414,357
- Date Initiated by Firm: November 20, 2023
The AirFit and AirTouch masks are non-continuous ventilatory devices, intended to be used by patients weighing more than 66 lbs. who have been prescribed non-invasive positive airway pressure (PAP) therapy such as CPAP or bi-level therapy. The masks are meant for reuse by one person at home or by multiple people in hospitals.
The devices have magnets on the lower headgear straps and frame connections of CPAP masks. These magnets are there to make wearing the mask more comfortable.
Reason for Recall
ResMed Ltd. is recalling all their Continuous Positive Airway Pressure (CPAP) masks with magnets due to possible magnetic interference with certain medical devices. Under certain circumstances when a magnet is in close proximity (less than 2 inches) to certain medical implants and devices, it might disrupt their function or position, possibly causing serious harm or death.
While the existing label advises keeping magnets 2 inches away from affected medical devices, it doesn't list all the specific ones that could be affected by the masks' magnets. ResMed is recalling these masks to update the labels, add more warnings and information to guide patients and health care professionals on safe usage when using masks with magnets. This recall and label update came after a review of potential risks to medical implants due to magnetic interference.
The use of affected masks may cause serious adverse health consequences and death.
There have been six reported injuries. There have been no reports of death.
Who May be Affected
- People who have been prescribed an AirFit or AirTouch mask for non-invasive positive airway pressure (PAP) therapy or bi-level therapy.
- Healthcare providers working in home-care or hospital settings who use an AirFit or AirTouch mask to administer non-invasive positive airway pressure (PAP) therapy or bi-level therapy.
What to Do
On December 8, 2023, ResMed sent all affected customers an Important Medical Device Advisory.
The letter requested customers to:
- Patients should reach out to their physician or the manufacturer of their implant or other medical device for further details regarding possible negative effects of magnetic fields on their device.
- Visit the ResMed Magnet Update website for detailed information about the recent updates made to contraindications and warning labels.
Customers in the U.S. with questions about this recall should contact ResMed at call 1-800-424-0737.
How do i report a problem.
Health care professionals and consumers may report adverse reactions or quality problems they experienced using these devices to MedWatch: The FDA Safety Information and Adverse Event Reporting Program using an online form, regular mail, or FAX.
Subscribe to Medical Device Safety and Recalls
Sign up to receive email updates on medical device recalls, safety communications, and other safety information.
NYC decision to move migrants from tent shelter to a school amid storm draws fire
New York City's decision to move nearly 2,000 migrants overnight from a tent shelter to a high school due to fears of an impending storm drew backlash Wednesday from parents of students at the school and others as the city struggles to house thousands of migrants seeking refuge.
The criticism included the city's continued use of the tent shelter on a remote, abandoned airfield in an area of Brooklyn that is at risk of coastal flooding from storms.
New York City Mayor Eric Adams said Tuesday afternoon that with winds up to 70 mph expected, the city was proactively relocating the migrant families from the tent shelter at Floyd Bennett Field in Brooklyn “out of an abundance of caution to ensure the well-being of those entrusted to our care.”
“While families are already in the process of temporarily being relocated, the city will ensure that essential services and the highest level of support are provided to all impacted by this decision,” Adams, a Democrat, said in a statement.
The shelter at Floyd Bennett Field is one of more than 200 sites New York City has established to house the surge of migrants arriving in the city since 2022 — largely as part of a busing campaign by Texas Gov. Greg Abbott, a Republican, who is seeking stricter security at the southern border. New York, which has a legal obligation to provide emergency housing to anyone who asks for it, has struggled to respond to the thousands of people arriving in the city.
Floyd Bennett Field has been widely regarded as a poor location for a shelter because it is far away from schools, transportation and other services and is vulnerable to the elements.
Images captured Tuesday night showed yellow school buses dropping off migrants holding young children and carrying bags with their belongings in the rain.
Students at James Madison High School in Brooklyn were informed Tuesday that classes would be conducted virtually on Wednesday because of the school's use as a “temporary overnight respite center."
“To ensure a smooth transition for families temporarily sheltering overnight in the building, our school building will be closed on Wednesday, January 10 and school will be in session remotely for all students,” Principal Jodie Cohen said in a statement to families.
The decision was decried by some parents who held a rally at the school Wednesday morning. One woman who said she is the mother of two students at the school called the situation “unacceptable.”
Alina, who did not share her last name, said she was “very angry” that the city “put our children last” and were instead “prioritizing the migrants.”
State Assemblyman Michael Novakhov, who represents the area and organized the rally, said the decision to relocate the migrants was “just really wrong. The school is not a right place for migrants, for anyone except the kids.”
He added that Floyd Bennett Field was “not a good place for temporary sheltering.”
“We have thousands of square feet of abandoned commercial property that we can use,” he said.
Zach Iscol, the commissioner of New York City Emergency Management, said at a briefing Wednesday that the school received hate calls and a bomb threat Wednesday morning. The bomb threat was cleared by police.
“These actions are not only deplorable, they’re also criminal offenses,” he said.
Floyd Bennett Field, along the shore of Jamaica Bay, was used for emergency relief during Hurricane Sandy in 2012, including housing 2,000 troops, according to the National Park Service.
Novakhov and others said the need to evacuate people demonstrated why the airfield should not be used as a shelter.
The Legal Aid Society and the Coalition for the Homeless said Tuesday that the “last-minute evacuation further proves that Floyd Bennett Field — a facility mired in a flood zone, miles from schools and other services — has never and will never serve as an appropriate and safe place to shelter families with children.”
The advocacy groups questioned whether the move would be “traumatic” and “disruptive” for the migrant families.
“We fear, especially with more inclement weather expected this winter, that this is only a foreshadow of more problems to come, and we again urge the City to cease placing families with children at this facility,” the groups said.
New York City Councilwoman Inna Vernikov said the city’s decision was “both unacceptable and was entirely foreseeable," because of the airfield's vulnerabilities to weather.
Vernikov called on the city to stop using public schools as shelters and said parents of the about 4,000 students at James Madison were “rightfully concerned.”
“This will agitate local residents, disrupt the entire school environment, and place a tremendous burden on our families, students, school administrators and staff,” she said.
Desiree Joy Frias, an organizer with South Bronx Mutual Aid, said outside the school that the city should focus on “moving people into permanent shelters so they can start getting jobs.”
“That is not the way we treat people. They’re not cattle. They’re not livestock. They are human beings with lives, with children, with human rights that are fundamental to them,” she said.
New York City has taken in approximately 170,000 asylum-seekers since April 2022 and currently has about 70,000 in its care, in addition to the homeless population, Iscol said at a briefing on Wednesday.
The city said that it projects to spend $4.7 billion to provide shelter, food and services to asylum-seekers in fiscal year 2024.
Iscol said at the briefing that “all of us understand in the city that Floyd Bennett Field is not an ideal place to be housing families with children.”
“The city has done a remarkable job making that place work,” he said.
Iscol said all of the migrant families were returned to the tent shelter overnight, beginning at around 1:30 a.m. Wednesday after getting the all-clear from the National Weather Service. Most people were transported out by bus from 3 a.m. to 4 a.m, he said.
He said that the city is making alternative plans should the tent shelter need to be evacuated again and does not foresee using James Madison High School again.
“No one wants to disrupt the lives of asylum-seekers nor those of our students, parents, teachers and principals,” he said.
Daniella Silva is a reporter for NBC News, focusing on education and how laws, policies and practices affect students and teachers. She also writes about immigration.
Andy Weir is an associate producer for NBC News.
Antonia Hylton is a correspondent for NBC News and MSNBC.
- Help Center
- Terms of Service
- Submit feedback
- Mark and track assignments
- Mark assignments
Mark and return an assignment
This article is for teachers.
In Classroom, you can give a numeric mark, leave comment-only feedback or do both. You can also return assignments without marks.
You can mark and return work from:
- The Student work page.
- The Classroom marking tool.
- The Marks page.
For instructions on the Marks page, go to View or update your student record .
For practice sets, learn how to mark a practice set assignment .
You can download marks for one assignment or for all assignments in a class.
Display assignments and import quiz marks
Before viewing a student's assignment, you can see the status of student work, and the number of students in each category.
Go to classroom.google.com and click Sign in.
- Click the class.
- At the top, click Classwork .
- Select the assignment to display.
- Tip: You can only get to the Student work page when the number isn't '0' for both 'Turned in' and 'Assigned'.
- Assigned – Work that students have to hand in, including missing or unsubmitted work
- Handed in – Work that students have handed in
- Marked – Marked work that you've returned
- Returned – Unmarked (non-marked) work that you've returned
- (Optional) To see the students in a category, click Turned in , Assigned , Marked or Returned .
- To check a student's submission, click on the assignment thumbnail.
- At the top right, click Import marks .
- Click Import to confirm. The marks autofill next to the students' names. Note: Importing marks overwrites any marks already entered.
- (Optional) To return marks, next to each student whose mark you want to return, tick the box and click Return . Students can see their mark in Classroom and Forms.
Enter, review or change marks
- Red – Missing work.
- Green – Handed in work or draft mark.
- Black – Returned work.
- Click the Student work tab.
The default marking scale is numerical based on the total points of the assignment. The expanded marking scales option is available for the Education Plus and Teaching and Learning Upgrade editions. You can align Classroom marking to your school's system whether:
- Alphabetical, for example letter marks (A to F) or proficiency (unsatisfactory to excellent)
- For example, four-point scales.
- For example, emojis.
Marking scales features work with:
- Average mark calculation
- SIS integration
- Practice sets and forms auto-marking
You can enter a mark either for the number of points or, if you have marking scales set up, based on the levels on the marking scale. For example, if you have letter marks set up in your class and you assign a 10-point assignment, under 'Mark', you can:
- Select Good 8/10 from the drop-down menu
- You and your co-teachers can find all marks in both points value and the level that it corresponds to.
A student can find both the points value and the level it corresponds to if a mark is returned.
- Next to the student's name, enter the mark. The mark saves automatically.
- Enter marks for any other students.
You can enter marks and personalise your students' feedback with the Classroom marking tool.
- Go to classroom.google.com .
- Optional: Under the classwork filter, select a marking period. Learn how to create or edit marking periods .
- Next to the student's name, and under the relevant assignment, enter the mark.
- The mark saves as a draft.
- Select Good 8/10 from the drop-down menu.
- If a mark is returned, a student can find both the points value and the level that it corresponds to.
- Optional: Enter marks for any other students and assignments.
Tip: You can return assignments without a mark.
- On the left, click a student's name.
- Click See history .
- Next to a student's name, click the mark that you want to change.
- Enter a new number. The new mark saves automatically.
Return work or download marks
Students can't edit any files attached to an assignment until you return it. When you return work, students get notifications if they're turned on. You can return work, with or without a mark, to one or more students at a time.
You can start with the default marking scale options, or create your own marking scale.
- In 'Marking', under 'Marking scale', click Add .
- Letter marks
- 4-point scale
- Create your own: Creates a custom marking scale.
- Edit the level and values of your marking scale.
- On the right, tick the box next to the class that you want to copy your marking scale to.
- Click Select .
- At the top right, click Save .
- When you edit a default marking scale, it becomes a custom marking scale.
- When you remove a custom marking scale that was previously used in a class, a confirmation dialogue displays, and you won't be able to access it again.
- The student's assignment is marked Returned.
- On the left, tick the box next to each student whose assignment you want to return.
- Click Return and confirm.
Download marks to Sheets
Download marks to a CSV file
- To download marks for one assignment, select Download these marks as CSV .
- To download all marks for the class, select Download all marks as CSV . The file is saved to your computer.
- Set up marking
- Give feedback on assignments
- Mark and return question answers
- Create and mark quizzes
- Mark and track practice set assignments
- Use a screen reader with Classroom on your computer
- Export marks to your SIS
Was this helpful?
Need more help, try these next steps:.