## Get current time with python time module

```
import time
print(time.time())
1586813438.419919
print(time.ctime())
Mon Apr 13 23:30:38 2020
```

## Get current time with python datetime module

```
import datetime
print(datetime.datetime.now())
2021–11–13 23:30:38.419951
print(datetime.date.today())
2021–11–13
```

## Get current time with python os module

```
import os
os.system(‘date’)
Sun Feb 20 10:12:36 UTC 2022
os.system(‘date +”%Y-%m-%d %H:%M:%S”’)
2022–02–20 10:30:09
```

[3 ways to get the current time in python](https://www.howtouselinux.com/post/3-ways-to-get-the-current-time-in-python)

[10 tips to use Python OS module](https://www.howtouselinux.com/post/10-tips-for-mastering-the-os-module-in-python)

--

--

1、len()方法

len()方法语法:len(list)

list — 要计算元素个数的列表。

示例:#!/usr/bin/python

list1, list2 = [123, ‘xyz’, ‘zara’], [456, ‘abc’]

print “First list length : “, len(list1);

print “Second list length : “, len(list2);

输出结果如下:First list length : 3

Second lsit length : 2

2、使用length_hint()方法查看列表长度

在Python中还可以length_hint()方法来查找列表长度。该方法是查找列表长度的一种鲜为人知的技术;它是在operator类中定义的,它会返回列表中存在的元素的数量。

代码示例:使用length_hint()方法来获取列表长度from operator import length_hint

初始化列表

List = [ 1, 4, 5, 7, 8 ]

输出列表

print (“列表为: “ + str(List))

list_len_hint =length_hint(List)

输出列表长度

print (“列表长度为: “ + str(list_len_hint))

how to check list length in python 3

--

--

Get list length in Python 3 Examples

Get list length with len() function

list = [10, 20, 30]

n = len(list)

print(“The length of list is: “, n)

Get list length with for loop

list = [‘Python’,’Java’,’Kotlin’,’Machine Learning’,’Keras’]

size = 0

print(“Length of the input string:”)

for x in list:

size+=1

print(size)

Get list length with len() function for nested list

nestedList = [‘Krishna’, 20,’John’, [20, 40, 50, 65, 22], ‘Yung’, 11.98]

print(“Original List = “, nestedList)

print(“Length of a Nested List = “, len(nestedList[3]))

​how to get the list length in python​

--

--

$uname -a

Linux ip-10–0–0–224 5.4.0–1045-aws

#47-Ubuntu SMP Tue Apr 13 07:02:25 UTC

2021 x86_64 x86_64 x86_64 GNU/Linux

more /proc/version

$ more /proc/version
Linux version 5.4.0–1045-aws

(buildd@lcy01-amd64–026)

(gcc version 9.3.0

(Ubuntu 9.3.0–17ubuntu1~20.04))

more /etc/os-release

$ more /etc/os-release
NAME=”Ubuntu”
VERSION=”20.04.2 LTS (Focal Fossa)”
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME=”Ubuntu 20.04.2 LTS”
VERSION_ID=”20.04″

lsb_release -a$lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal

how to check os version

--

--