python에서는 변수를 정의하여 사용한다. 단, Java 등의 다른 언어는 변수의 type을 먼저 지정하고 입력을 해야한다. 그러나 python은 그 과정이 필요없다.
In case of python
x=10
y="abc"
in case of Java
int x=10
string y="abc"
그리고 python에서 변수명을 지정할때 주의사항이 있다.
x=10
y="abc"
print("x : {}".format(x))
print("y : {}".format(y))
print("x : {} and {}".format(x,y))
>> x : 10
>> y : abc
>> x : 10 and abc
Java에서는 문장을 구분할때 ";" 사용하지만, python에서는 사용하지 않는다.
그러나 아래와 같이 사용하는 것도 가능하다.
x=10; y=20; z=x+y
print("z : {}".format(z))
>> z : 30
연습삼아 출력문을 작성하는 예시 들을 작성^^
name="seik"
score=100
print("Total score for %s is %s " % (name, score))
print("Total score for {} is {}".format(name, score))
print("Total score for", name, "is", score)
>> Total score for seik is 100
>> Total score for seik is 100
>> Total score for seik is 100