---
# System prepended metadata

title: Week Five at the Blockfuse Labs

---

# Week Five at the Blockfuse Labs 
# Python Programming Language: Data types, String Slicing, String formating, Split

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics (python.org). In the past week, we learned about data types in python, string slicing, string formating and split. 

**Data Types in Python**
Data types define what kind of data a variable can hold and the operations that can be performed on it. Most common among these data types are: 
a. ***Numeric data types*** such as 
*  *Integers (int):* made up of whole numbers which may either be positive numbers like 10, 5, 100 or negative numbers like -3, -55 etc. 
*  *Floating-point numbers (float):* which consists of decimal numbers like 12.6, 2.5, -10.1, -0.2. 
*  *Complex numbers*: these are written in the form of 12j.  

b. ***Text data type*** which consist of strings. 
Strings (str) are text enclosed in single or double quotes, for example, 'Hello', "World" "Python". It is important to note that in strings, when you start a text with a single quotaion mark, you can't end it with a double quotation mark e.g., you can't do 'Hello" or "World', this is a wrong syntax. 

c. ***Booleans (bool)***: these are logical values such as True or False. These true or false values are not enclosed in quotes, otherwise they become string data type. 

d. ***Sequence:*** sequence data types are used to store an ordered collection of items which maybe of the same or different data types and are indexed numerically (starting from 0). Examples of this are: 
* Lists (list) : Ordered, mutable collections like [1, 2, 3, 4, 5] or ["James", "Tom", "Jane"]. Mutable in the sense that the values can  be changed or reassigned after they have been created. 
* Tuples (tuple) : Ordered, immutable collections like (1, 2, 3). Meaning that they cannot be reassigned or changed after they are created. 
* Dictionaries (dict) : This is known as a key-value pair because it contains a key and a value. For example: user1 =  {'name': 'Kris', 'age': 15}.
* Sets (set) : The set looks like a dictionary but they do not come in key-value pairs. Set is used to store an unordered collections of unique elements like {1, 2, 3} or {"Tom", "Jerry", "Mac"}. 

**String Slicing** 
Slicing in python allows the user to extract a portion of a string by specifying start and end indices. That is, it usually has a start value and an end value but the end value will not be included in the portion collected. In Python, the square brackets [] is used for slicing.
Slicing sequence is denoted by: [start:stop:step]
The step signifies the number of steps to move between characters and is usually optional. 
Example: 
bio = "programmer"
         print(bio[1:5])
         outputs ---> rogr
        
Note that negative values can also be used in slicing but they usually start from -1 and not 0. 
Example: 
technology: "blockchain"
chain = technology[-5:]
print(chain)
outputs ---> chain. 

The user can also change a string to either uppercase or lowercase by attaching either .upper() 
--->for uppercase string value, or .lower()   
----> for lowercase string value. You can also use the .capitalize() 
----> to capitalize the first item on the string. 

**String Formatting** 

String formatting allows the user to insert variables into strings dynamically. There are different ways to format strings in python shown below:

![format](https://hackmd.io/_uploads/ry4FTwWUge.png)

**Split**
The split() method allows the user to break a string into a list of substrings based on a specified delimiter. A delimiter defines how data is separated in a string. Common delimiters include: Comma , Space ' ', Tab \t, Semicolon ; Newline \n. 

Example:
![Split](https://hackmd.io/_uploads/SJ8kQu-Ulg.png)

**Conclusion**

There are many concepts to learn in python programming and mastering these concepts will give the user an edge as well as a solid foundation in python programming and prepare you for more advanced languages. 
