Issue
I'm a programming student and my teacher is starting with C to teach us the programming paradigms, he said it's ok if I deliver my homework in python (it's easier and faster for the homeworks). And I would like to have my code to be as close as possible as in plain C.
Question is:
How do I declare data types for variables in python like you do in C. ex:
int X,Y,Z;
I know I can do this in python:
x = 0
y = 0
z = 0
But that seems a lot of work and it misses the point of python being easier/faster than C. So, whats the shortest way to do this?
P.S. I know you don't have to declare the data type in python most of the time, but still I would like to do it so my code looks as much possible like classmates'.
Solution
Edit: Python 3.5 introduced type hints which introduced a way to specify the type of a variable. This answer was written before this feature became available.
There is no way to declare variables in Python, since neither "declaration" nor "variables" in the C sense exist. This will bind the three names to the same object:
x = y = z = 0
Answered By - Ignacio Vazquez-Abrams
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.