Basic Python I

Rifqi Aulya Rahman
3 min readDec 29, 2021

--

This blog will give you some basic codes or syntax python for the beginner. It is so technical, and I hope you all can follow it step-by-step.

Photo by Clément Hélardot in Unsplash

Variables

Assign value to variable, then print it

You can know a type of variable from that

int = integer, float = decimal number/real, str = string.

Numbers

For operation between numbers, you text

for subtraction (-), multiplication (*), division (/), truncating (//), modulus (%) and exponentiation (**). How to get truncated and remainder at once, we can use divmod(integer, integer).

Conversion

Changing the data type to an integer, we use

and to change the data type to a float, we use

Strings

Making string by enclosing characters in single/double quotes, like

Function str() can use in conversion technic too. Python lets you escape with \ such

Combining the strings by+ as

Extract a Character

To get a single character form string, python use function []. The first offset is 0, the next is 2, and so on. The last offset (rightmost)can be specified with -1, going to the left,-2 , and so on.

Next, you can change a character in a string with

or you slice a string with [start: end: step]

or you split/join a string to string by separator

The length of a string is counted by

Lists
Lists are keeping track of things by order. Create lists by [] or list()

To convert string to list is given with

Extracting a element in list

For your information, lists can contain of different types, including other lists. Next, the list element can be changed like

Adding list by list is texted by

--

--

Responses (1)