A newbie question about Python Variables

0 Richie Butterton · July 6, 2015
Is the Variables considered equivalent to a Class like in C#? is it the same meaning?

I'm a new lad keen to learn but I just wanted to make sure as I learn things, I want to get to know what I'm learning completely before moving onto the next thing to what I'm being taught. ;)



- Richard Butterton

Post a Reply

Replies

Oldest  Newest  Rating
+2 alex constantin · July 6, 2015
No, a class in C++ would be equivalent to a class in Python!

A variable in python would be like this, for example: An integer called points which holds 500.

In python, you do not need to specify the data type, python does it for you
points = 500 #integer var
title = "My Awesome Title" #string var
is_logged_in = True #boolean var
0 Richie Butterton · August 8, 2015
Thanks for the kind responses, I kept checking Google Mail for a notification instead of checking here ;3 I've gotten a better understanding to it now thank you again. Though I've decided in the end to go for C# but really glad this community is friendly ;3
0 Otto Von Chesterfield · July 7, 2015
To elaborate on alex constantin's explanation, Python variables are what as known as "dynamically enforced", meaning that, in general, programs don't really care what type of object something is, be it string or int, as long as it can get the job done the program wants it to do. For example:

def sum(v1, v2):
  return v1 + v2

The above code can work not just for numbers, but for strings too - in fact, any object that has the .__add__ method.
This is only part of the beauty of working in Python.
  • 1

Python

107,202 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator