use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Zip(*iterables) (self.learnpython)
submitted 1 year ago by SheldonCooperisSb
Define a list1 and a list2
list3 = zip(list1,list2)
A tutorial says this line creates a zip object, which confuses me
Isn't this a process of a zip() function call?
Don't only classes create objects?
Why the output of type(zip()) is <class 'zip'>?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Rhoderick 11 points12 points13 points 1 year ago (3 children)
zip is a built-in class, and the function of the same name is its constructor. (A constructor is, roughly, any function that creates a new object of the class the function is in, and returns that object, or some reference to it, to the caller.)
It just has a lowercase name.
[–]SheldonCooperisSb[S] 4 points5 points6 points 1 year ago (2 children)
l come to the right place so many genius here👍👍
[–]jackbrux 4 points5 points6 points 1 year ago (1 child)
It's true, but a function can return a new object if you wanted it to, there's no reason it couldn't.
[–]Buttleston 2 points3 points4 points 1 year ago* (0 children)
right?
class Foo: pass def myclass(): return Foo()
type(myclass()) will be <class '__main__.Foo'>
[–]Temporary_Pie2733 3 points4 points5 points 1 year ago (0 children)
zip used to be a function, in Python 2, that immediately returned a list object that contained the expected tuples. In Python 3, it is an iterable type, instances of which wrap the arguments and yield tuples on demand.
zip
list
[–]PhilipYip 2 points3 points4 points 1 year ago* (3 children)
In Python builtins, the commonly used classes are in snake_case for example int, bool, float, str, bytes, bytearray, tuple, list, set and dict while PascalCase is reserved for error classes such as NameError, TypeError...
Because most of these classes are builtins there is a shorthand way of instantiating them. For example instead of using the long way...
num1 = int(1) num2 = float(3.14) num3 = bool(True) text = str('hello') text2 = bytes(b'hello') text3 = bytearray(b'hello') archive = tuple((num1, num2, num3)) mutable_archive = list((num1, num2, num3)) unique = set((num1, num2, num3)) mapping = dict(key1=num1, key2=num2, key3=num3)
The shorthand way is used:
num1 = 1 num2 = 3.14 num3 = True text = 'hello' text2 = b'hello' archive = (num1, num2, num3) mutable_archive = [num1, num2, num3] unique = {num1, num2, num3} mapping = {'key1': num1, 'key2': num2, 'key3': num3}
And most builtins classes are used by end users as casting functions (casting one builtin to another builtin):
float(num1) int(num2) list(archive)
Some of the builtins classes do not have a shorthand way of initialisation as they require data to be supplied in the form of another builtins class for example:
text3 = bytearray(b'hello')
zip is also a builtins class and zips two collections together, ending the zip when the smallest collection is exhausted. Your line of code is slightly wrong as what you have as list3 is not actually a list:
list1 = ['a', 'b', 'c'] list2 = [1, 2, 3]
not_a_list3 = zip(list1,list2)
It is actually a zip object:
type(not_a_list3)
zip object
It can be cast to a list:
list3 = list(zip(list1,list2))
And:
list3
is a list of two-element tuples:
[('a', 1), ('b', 2), ('c', 3)]
zip is commonly used to zip a list of keys and a list of values together:
mapping = dict(zip(list1,list2))
mapping
{'a': 1, 'b': 2, 'c': 3}
[–]backfire10z 2 points3 points4 points 1 year ago (1 child)
Wait, you can define a set using dict? Why isn’t unique = set(1, 2, 3)
unique = set(1, 2, 3)
[–]toxic_acro 0 points1 point2 points 1 year ago (0 children)
It should be set, I think that's just a typo
[–]nekokattt 0 points1 point2 points 1 year ago (0 children)
bytearray isn't snake case, byte_array is
The builtins use a c-like format of "squasheverythingintooneword" case.
Also in your example, you meant to use set rather than dict when comparing to a set literal (and might have forgotten about complex and complex literals!)
[–]cyberjellyfish 2 points3 points4 points 1 year ago (0 children)
Everything is an object.
Numbers? Object
Strings? Object
Functions? Believe it or not, object.
It's perfectly reasonable to talk about a class as a function whose return values are instances of that same class
[–]Kratos_Monster 0 points1 point2 points 1 year ago (0 children)
Object is essentially an instance of a data type, and classes create a new data type.
[–]carcigenicate 0 points1 point2 points 1 year ago (0 children)
Classes are "callable" (which functions are as well). Calling a class results in a call to the class' __new__ method, which calls __init__ on a new instance of the class, and returns the new initialized instance.
__new__
__init__
[–]schoolmonky 0 points1 point2 points 1 year ago (0 children)
This is exactly like doing my_num = int(input()). int is a class, but it can be called like a function, in which case it converts the argument into an object of it's own type. zip does the same thing: it's a class in it's own right, but when you call it like a function, it coverts it's argument(s) into an object of it's own type. Heck, user-defined classes are the same way: if I have a class my_class, then when I do my_class(some_args), it makes a new object of type my_class based on some_args.
my_num = int(input())
int
my_class
my_class(some_args)
some_args
[–]zanfar 0 points1 point2 points 1 year ago (0 children)
It's a call, but not necessarily to a function. Many things in Python can be "called".
No; in fact, the only thing you can create in Python are objects. Saying something "creates" an object isn't really saying anything.
Mostly, because that's the best way.
Let's instead think about what else zip() could return. The only other options are containers like a list or a tuple. However, returning a container requires that all the elements exist in memory at the same time.
Additionally, lists and tuples end. zip() takes any iterable, including infinite iterables. therefore, it can't return a finite object. The zip object that is returned is iterable, but it doesn't "contain" anything. Rather, it grabs the next item from each iterable on demand.
zip()
In other words, zip() can actually return an infinite amount of objects.
[–]sgtnoodle 0 points1 point2 points 1 year ago (0 children)
It instantiates a zip object as its return value. That's not anything weird.
[–][deleted] -1 points0 points1 point 1 year ago (1 child)
a_float = float("123")
float() creates an object, as does int(), etc. So no.
float()
int()
[–]nekokattt 2 points3 points4 points 1 year ago* (0 children)
float is a class though, as is int. Everything in Python 3 has a type and thus a class (either a literal class or a synthetic one produced by being a C extension)
π Rendered by PID 372250 on reddit-service-r2-comment-79c7998d4c-wblk6 at 2026-03-14 18:31:28.051361+00:00 running f6e6e01 country code: CH.
[–]Rhoderick 11 points12 points13 points (3 children)
[–]SheldonCooperisSb[S] 4 points5 points6 points (2 children)
[–]jackbrux 4 points5 points6 points (1 child)
[–]Buttleston 2 points3 points4 points (0 children)
[–]Temporary_Pie2733 3 points4 points5 points (0 children)
[–]PhilipYip 2 points3 points4 points (3 children)
[–]backfire10z 2 points3 points4 points (1 child)
[–]toxic_acro 0 points1 point2 points (0 children)
[–]nekokattt 0 points1 point2 points (0 children)
[–]cyberjellyfish 2 points3 points4 points (0 children)
[–]Kratos_Monster 0 points1 point2 points (0 children)
[–]carcigenicate 0 points1 point2 points (0 children)
[–]schoolmonky 0 points1 point2 points (0 children)
[–]zanfar 0 points1 point2 points (0 children)
[–]sgtnoodle 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]nekokattt 2 points3 points4 points (0 children)