2014-06-17 2 views
-2

파이썬 3에서이 코드를 실행하고 싶지만 코드를 실행하려고 시도 할 때마다 유효하지 않은 구문 오류가 발생합니다.python 3 버전에서이 코드를 사용하는 방법은 무엇입니까?

age = 20 
name = 'Swaroop' 
print '{} was {} years old when he wrote this book'.format(name, age) 
print 'Why is {} playing with that python?'.format(name) 

도와주세요.

감사합니다.

+1

확인해보십시오. https://docs.python.org/3/whatsnew/3.0.html#print-is-a-function –

답변

1

print괄호 안의 내용은입니다.

print('{} was {} years old when he wrote this book'.format(name, age)) 
print('Why is {} playing with that python?'.format(name)) 
Python2에서

, print는 성명이며, 괄호가 필요하지 않습니다.

In Python3, print is a function이므로 인수를 둘러싼 괄호가 필요합니다.

관련 문제