DEV Community

Davisonyeas
Davisonyeas

Posted on

3 2

Getting Started With Python PyStart(Variables)

1.0 VARIABLES
Variables are containers for storing data values. Python has no command for declaring variable. A variable is created the moment you assign a value to it.
For example,

x = 4;
Enter fullscreen mode Exit fullscreen mode
y = "Davis"
Enter fullscreen mode Exit fullscreen mode

To display the result of this, We make use of the print() built-in function;

print(x)
Enter fullscreen mode Exit fullscreen mode
print(y)
Enter fullscreen mode Exit fullscreen mode

Output
4
Davis

Note:
In Python, we do not have to say x = int 4; just as we have in other programming languages like Java, Python automatically detects the data type of the value)

Also, when declaring variable names, we take note of keywords, there are some reserved keywords in python that shouldn't be used as a variable name, some of such keywords includes return, is, continue, def, finally, and a few other words. Read further on Python keywords Click here for Python keywords

1.1 Checking the data type of the variable
It is important that we know how to check data types in Python, this is a basic concept that will come in handy when we get to more advanced topics like Data Preprocessing and Analysis.
We check the type of our data by using the type() method.

print(type(x))
Enter fullscreen mode Exit fullscreen mode
print(type(y))
Enter fullscreen mode Exit fullscreen mode

Output
int
str

1.2 Python Variable Naming Rules
The following are the some good, bad and different naming conventions.
The Good shows some good naming conventions that can be used and that is accepted by developers.
The Bad shows some bad practices that shouldn't be used while coding.
The Different shows that each individual variable is independent of the others, they all have the same spelling but the fact that some are capital letters and some aren't. They are all different.

Good: spam  eggs  spam23  _speed
Enter fullscreen mode Exit fullscreen mode
Bad: 23spam  #sign   var.12
Enter fullscreen mode Exit fullscreen mode
Different: spam   Spam   SPAM
Enter fullscreen mode Exit fullscreen mode

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

Top comments (0)

Image of Stellar post

🚀 Stellar Dev Diaries Series: Episode 1 is LIVE!

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay