Do you get content of oper right before trying it out?

oper = ['plus', 'minus', 'times']
oper.extend('divide')

How about do you know what happens when you run this? Big bang? ;)

print('a'
      'b'
      'c')

And this is same, isn't it`?

c = 'c'
print('a'
      'b'
      c)

Recommended Answers

All 3 Replies

I dont know why but extend adds 'devide' as another list to oper.
I couldn't find "extend" function for lists!

Strange and amazing, using new line in second example somehow works like a "+" opperator. but fails when we use a variable instead of a string.

the below works as the fist one:

c = 'c'
print('a'
         'b'+
         c)

Here's the extend part from the Python Documentation:
Extend.
As for

print ('a'
       'b'
       'c')

it's the same with

print ('a' 'b' 'c')

as for the

c='c'
print ('a'
       'b'
        c)

think of it as

c='c'
print ('a' 'b' c)

where c is a variable, and not a given character. Even if you declared c as a string/character, you can't print them together as for

c='c'
print ('a' 
       'b' 
       '{}'
       ).format(c)

#or
c='c'
print ('a' 'b' '{}').format(c)
#it's the same with the first print.

I dont know why but extend adds 'devide' as another list to oper

No.

I couldn't find "extend" function for lists

Have you even looked?
Help from interactive interpeter.

>>> help(oper.extend)
Help on built-in function extend:

extend(...)
    L.extend(iterable) -- extend list by appending elements from the iterable

The keyword here is iterable.
Here is an other one with extend,this one is harder to guess and is it possible to guess exact output?

l = [1, 2, 3]
d = {4: 5, 6: 7, 8: 9}
l.extend(d)
print l #?
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.