‘Hello everyone, it’s Ruby again.
In this session, we learnt about data types and using the input function. Every value in a programming language has a data type. A data type tells the computer what kind of value to expect.
There are 4 data types:
- Integers – They are whole numbers. There is no limit to how long an integer value can be as long as your computer has enough memory space. Integers are written as int. For example: print(6) print(246810121416182022242628303234363840 + 1)
- Floating-point numbers – They are decimal numbers. Float represents these type of numbers. For example: print(4.2 + 5)
- Strings – They are a set of characters. The string type is represented by str.
- Boolean – This type may have one or two values: True or False. The type is called bool. We use Boolean values in programming to make comparisons and to control the flow of the program. For example: print(5 == 5)print(5 == 6)
You can check the data type of a variable. For example: the_value = 10print(type(the_value))<type ‘int’>
The difference between a single equals sign and a double equals sign is that a single sign is an assignment operator, whereas two equal signs are a comparison operator.
The == operator is one of the 6 comparison operators;
- x != y – x is not equal to y
- x > y – x is greater than y
- x < y – x is less than y
- x >= y – x is greater than or equal to y
- x <= y – x is less than or equal to y
After the break, we learnt how to use the Input function. Since we started learning Python, we have been using the output function print (). The print function tells the computer to display certain values. The input function, represented by input (), accepts user input from an device such as a keyboard. It converts the input in to a string and returns the value. For example: name = input (‘What is your name?’) print (‘Hi’, name, ‘, nice to meet you!’)
At the end of the session, we were given homework to do exercises on our sheets. I enjoyed the session. Go Girl will be back on Wednesday 24th.
I hope you all have a lovely Easter and I shall see you on the next blog post!’