Concatenate string and int in python 3.4

前端 未结 6 2086
青春惊慌失措
青春惊慌失措 2021-01-06 05:27

I\'m new to Python, so I\'ve been running through my own set of exercises to simply start memorizing basic functions and syntax. I\'m using Pycharm IDE and Python 3.4. I\'ve

6条回答
  •  一整个雨季
    2021-01-06 05:59

    Please remember (or if you don't know it yet, read up on the subject) that print is a function in Python 3. In Python 2, your first line would concatenate "Type string: " and "123" and then print them. In Python 3, you are calling the print function with one argument, which returns None, and then add "123" to it. That doesn't make any sense.

    The second line doesn't generate an error in Python 2 or 3 (I've tested it with 2.7.7 and 3.2.3). In Python 2, you get

    Concatenate strings and ints 10

    while in Python 3, your script should only print

    Concatenate strings and ints

    This is because again, print is a function, therefore you call it with the argument "Concatenate strings and ints". The , 10 makes your line a tuple of the return value of print, which is None, and 10. Since you don't use that tuple for anything, there is no visible effect.

提交回复
热议问题