Discovering Python as a Codenewbie
For a prospective job opportunity, I have to write the code using Python. However being that I am more comfortable with Ruby and JavaScript and am not familiar with Python. I thought that this would be an amazing opportunity to learn a new language. And I decided to share with you what I learned about Python and maybe this will inspire you to discover Python. I used the Python Documentation and a Python course on Udemy as a resource to learn and write this blog post, which might become a series of blog posts.
I thought that this particular blog post would cover some basic topics of Python like variables, strings, print() method, format() method and comments.
print() method
print() method -> print something like text or a string in a terminal so the user can see them.
Comments
If you’d like to include comments in your Python code you can use the # sign.
Strings
In Python, strings can be written in single quotes or double quotes.
Variables
Using variables in Python is straightforward. You do not need to declare variables. Instead you can choose a name and assign the value directly as you can see in the following example:
format() method
Let’s say that you want to print a statement with the age variable like this one:
{} is a placeholder for something else which can be the age variable and what we do is reformat the string to replace this placeholder with age by typing out our string and then add .format(age)
.format() -> replaces whatever is inside the curly brackets with the variable you want to add in
Now this statement with print out:
Overall it has been a great experience learn Python so far. By reading the Python documentation, and understanding the beginning concepts of Python, I am expanding my knowledge and look forward to learn additional concepts of Python. Thank you for reading this blog post and I hope you learned something new.