I have always liked the idea of knowing a coding language. It makes me feel geeky and since most people will immediately sideline coding as a scary thing to learn, I feel the adrenaline rush to learn it. During my university days, I took a minor where I learnt the Java language. It was not easy at all. I did not have a hidden talent for computing and I spent many hours just reading discussion forums to find the solution that I need.
Luckily the experience did not haunt me into giving up on coding. I am happy that I complete the course and challenged myself.
Did I continue to practice Java coding? Well, I did not. My job as a secondary school science teacher did not need that. I merely taught my students Scratch as part of their applied learning programme, which required only my basic understanding of the coding principle.
This year 2021, I read about data analytic, the trending job. I read about the job scope, the expectations of the job, watch youtube videos on how to land a data analyst job. Many companies mentioned either R or Python as one of the job requirement.
I bought a Udemy course called Data Analyst Bootcamp. As the course was targeted to train on skills for a data analyst, they give specific examples and bring you through the thought process as well as the coding steps to achieve the outcome. I completed the course by mirroring the examples. However, I find it hard to apply the concepts I learnt in the course. Partly because I had not worked with large datasets before and was unable to create problems to make use the python on data.
In May I registered for the SGunited Mid-Career Pathways Programme called RISE (Rapid and Immersive Skill Enhancement) by Boston Consulting Group (BCG). The programme started in July and they gave us introductory lessons on python. I worked through the basic examples quickly thinking I had nailed it. After reviewing the teacher's answers, I realised I was using more complicated statement to achieve the same results and that was because I do not understand how to use some of the syntax.
Eventually I worked through the examples and here is the consolidation of my learning.
- print() = to print whatever it within the () as a output. If you did not print (), there will only be output for the last line of code appearing as output on jupyter after you run the code.
- type() = to show the type of input. There are string (str) for letters, integer (int) for whole numbers or float for decimals. This is crucial, since in coding we cannot use two different types of input in the same line.
- assigning value to a variable using the '=' sign. eg. var = "Hello"
- print with a gap using a ','. eg print("$", 5) = $ 5. Comma allow us to combine str and int in the same statement unlike "&" and "+" sign which can only concatenate two of the same type of input together however it does not work for my eg which is a string and an integer.
- input() = allow you take in input by the user. I had alot of fun with this. eg1. get = input() will give a blank box for the user to fill in and that input will be assigned to get.
eg2. input("Remind me to:" ) will give the blank box beside the your string "Remind me to:"
This is neater instead of having to type another line of print() before.
- The use of " and '. Both have the same function however using a different one allowed you to print this sign. Otherwise it is just to show whatever inside a string. If you use 3 of the same ' or " at the start and end, it will allow you to print multiple lines at once instead of printing each individual line.
# [ ] ASCII ART
| 6 6 |
| @@ |
- # is for comments. It is important to add in comments to facilitate other people reading your codes. It is also useful to write in full and clear variable names instead of shortforms that maybe only you understood.
- to check if certain string formatting is true.
.isalpha() for alpha numeric
.isalnum() for all number
.isupper() for if all capitalized
eg. print(input().lower()) will print the output of true/false if the input is all lower case.
- indexing starts at 0
# [ ] print True or False if color starts with "b"
colour = input("color is: ")
print(colour == "b")
so this will return true or false if the first letter of user input is equal to the letter "b".
A single "=" sign is for assigning the value while double "=" is an equality
- capitalize() / swapcase() / lowe() / upper() allowed you to format the string.
- "in" keyword allowed you to check if the short string is inside the long string
eg. # [ ] print true or false if 'cat' is in the string variable animals_input
animals_input = input("Guess the animal: ")
animals = "tiger dog cat bird bear"
print(animals_input in animals)
it will return true if cat is inside the list of animals string
**if case sensitivity is not important then it is good practice to .lower() both the search string and the search target to ensure a more effective searching. Else we will just run into a problem to ensure all are in the exact case.
-"def" for creating functions. Functions are like macro in excel, a set of actions to be taken on the inputs and return the result. The codes under the def must be indented. We can also make a def without the requiring inputs. eg def try():
addition = num1 + num2
addition(1,2) will give return me the answer 3
-if else elif = conditional statements
This is one of the common decision tree keyword that you can find in all coding languages. It allows you to make elaborate programmes that take in input and process it differently based on the condition set.
age = int(input("Enter your age: "))
if age >= 12:
print("You will be",age + 10, "in 10 years!")
print("It is good to be", age)
The first "int" in age = int(input("Enter your age: ")) cast the input as an integer. And it will process it to give a statement according to the number given.
Setting default argument
def yell(phrase = 'how do you do"):
print (phrase.upper() + "!")
yell("good day") will return GOOD DAY!
yell() will return HOW DO YOU DO
return keyword allow functions to send back a value to the function.
pass (meaning there is nothing for else loop)
I enjoyed all these little puzzles, it is really fun when you managed to write the codes and the computer return you the correct answer that you want it to.
Till the next consolidation!