Please enable JavaScript.
Coggle requires JavaScript to display documents.
basic python program, A string is a collection of characters (strings can…
basic python program
-
Data types and variables
When first starting out with Python, you’ll need a strong grasp on the different data types available to you and how to assign variables, which allow you to store data that can then be used later on throughout your code.
Unlike many other languages, Python does not place a strong emphasis on defining the data type of an object, which makes coding much simpler
Boolean
The Boolean (also known as bool) data type allows you to choose between two values: true and false. A Boolean is used to determine whether the logic of an expression or a comparison is correct. It plays a huge role in data comparisons.
numbers
-
-
-
-
Integers are comprised of all whole numbers. Each integer has memory associated with it, so for example 0 will take up 24 bytes and 1 will take up 28 bytes.
-
Refer to positive and negative decimal numbers such as 3.1, 5.0, -3.24543.
-
Complex numbers require two values; the first is a real part of the complex number and the second value will be imaginary and is represented with a j.
Variables
A variable is simply a name to which a value can be assigned to give better clarity and management to your code, so if someone was to read your code they would know what’s going on and what each variable means.
If-else statement
The if-else statement allows for even greater control over program. The statement says that “if this condition is true, execute the code, else execute other code snippet”. Now you have the ability to perform two different actions based on the condition’s value, whether it be true or false.
loops
A loop is a control structure that is used to perform a set of instructions for a specific number of times — effectively solving the problem of having to write the same set of instructions over and over again.
One of the biggest applications of loops is traversing data structures, e.g. lists, tuples, sets, etc. In such a case, the loop iterates over the elements of the data structure while performing a set of operations each time.
A string is a collection of characters (strings can also be empty) closed within single or double quotation marks. We’ve all seen the classic Hello World example, well that’s a string. Notice how that example uses a single quotation mark, but if you wanted to say “Hello world it’s me!” you would need to use double quotation marks because there is an apostrophe in the word “it’s”. If you were to try with single quotes you wouldn’t get your desired string.