1

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)

Edited by pyTony

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by snippsat
0

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)
0

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.

Edited by Lucaci Andrew

0

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 #?

Edited by snippsat

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.