I DON’T SPEAK GERMAN (BUT I CAN IF YOU LIKE)

--Originally published at Coding The Future

If you are a Lady Gaga fan, you are probably familiar with her famous line "I don't speak German, but I can if you like" from her song SchieBe. This lyric line has always intrigued me, but it has acquired a new meaning since I started programming. Why? Because once you learn an object-oriented language, all others come naturally in a matter of days.

I started coding on Python 3 for the first time last week, and coming from C# on Visual Studio 2008 felt like a natural transition. All the syntax is pretty much the same, and some is even simpler, which is an amazing thing!

I have taken the time to compile the most basic syntax that I've learned on Python so far. Enjoy!

1. Comments

When we think about coding, commenting often goes as an underestimated feature. Consequently, I decided to start my post with comments.

#COMMENTS: To comment, use a number sign and then write your comment.

2. Declaring variables (and arrays)

Unlike other programming languages, I've realized that on Python, you don't have to declare the variable type when declaring a variable. To declare a variable, just type the name, and if you want to, give it a value. Even though you don't need to, I usually give integer-type variables a default value of zero. You can also declare strings and arrays using the appropriate brackets.

i = 5 j = 6
k = i + j
y = [1,3,5,8]
x = ('Emanuel')

3. Output

To output a variable or just some text, you can use the print class. Remember you can always combine several variables or variables with text by concatenating using the plus sign.

print ('Hello World!') print ('Hello, ' + x)
print (k)
print (y)
print (y[2])

4. Input

I'll be with you: I'm still working on this one. But I already figured out how to ask for user input as long as all you need is a string input. As soon as I figure out how to input integers I'll update this article. The following example asks the user for their school's name and then prints it telling them their school rocks!

school = input("What school do you go to? ") print (school + " rocks!")

5. Loops

Loops are an essential in the programming world, because otherwise, we would have to code the same things over, and over. In python, both while and for loops are as easy as it follows:

while (i >= 1): print ('Hello, ' + x) i = i - 1

for letter in "Hello": print (letter)

Best part... No need for {brackets}, just watch your indentation.

5. If statements

Lastly, if statements look very similar to loops. All you have to do is declare the if and else conditions and do proper indentations:

if (k >= 10): print ("The third line is a number greater than ten") else:
print ("There's something wrong!")

Obviously, there is a lot more syntax that exists in Python 3, but for today, this is all we will be touching upon. Stay tuned for more content coming soon. For now, have a Gaga day!

-- If you have any questions, feel free to tweet me @emamex98.

-- Cover image by popUrself.