Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
958 views
in Blog Post by 6 8 12
edited by

In this post, we will list most of commoun Python methods that you should to know as a beginner

Python List Methods

  1. sort()
  2. Math Modules
  3. Random Modules
  4. Datetime

 sort()

Math Module

  • Remainder() or %

import math
print (26%5)
  • sqrt()

import math
numbers = 144
print (math.sqrt(numbers))

Random Module

  • random()

import random
print (random.randint(0, 9))

 

Python Operators

First_name = 'Reemaz'
second_name = 'alaa'
print (First_name*3)

First_name = 'Reemaz'
second_name = 'alaa'
print (First_name + second_name)

Note: To add a space between them, add a " "

First_name = 'Reemaz'
second_name = 'alaa'
print (First_name + ' ' + second_name)
  •  datetime to string using strftime()

The table below shows all the codes that you can pass to the strftime() method.

Directive

Meaning

Example

%a

Abbreviated weekday name.

Sun, Mon, ...

%A

Full weekday name

Sunday, Monday, ...

%w

Weekday as a decimal number.

0, 1, …, 6

%d

Day of the month as a zero-padded decimal.

01, 02, ..., 31

%j

Day of the year as a decimal number.

001, 002, ..., 366

%b

Abbreviated month name.

Jan, Feb, ..., Dec

%B

Full month name.

January, February, ...

%M

Minute as a zero-padded decimal number.

00, 01, ..., 59

 

%m

Month as a zero-padded decimal number.

00, 01, ..., 59

%Y

Year with century as a decimal number.

2013, 2019 etc.

%y

Year without century as a zero-padded decimal number.

00, 01, ..., 99

 

%H

Hour (24-hour clock) as a zero-padded decimal number.

00, 01, ..., 23

%I

Hour (12-hour clock) as a zero-padded decimal number.

01, 02, ..., 12

%p

Locale’s AM or PM.

AM, PM

%S

Second as a zero-padded decimal number.

 

 

00, 01, ..., 59

 

 

%f

Microsecond as a decimal number, zero-padded on the left.

000000 - 999999

 

For Example

import datetime
date = datetime.date(2020, 2, 13)
time = datetime.time(14, 5, 17)
print (date)
print (time)
print date.strftime('%A %B %Y')
print time.strftime('%I %M %S’)

Functional programming In Python

 

 

 


If you don’t ask, the answer is always NO!
...