styleru.py lecture 1

ilebedev

			styleru.py
		

Что за ужас тут творится?

Что за ужас тут творится?

Почему Питон

Версии

2.7.10 3.5.0

Релизации

Релизации

Консоль

Консоль

			ls cd mkdir cp mv rm cat tail grep
		
			python pip
		

Гит

 

				users = [
				  {'login': 'ilebedev', 'email': 'melevir@python.ru'},
				  {'login': 'kazauwa', 'email': 'kylehydeme@gmail.com'},
				]
				 
				for user_num in range(len(users)):
				  print(user_num, users[user_num]['email'])
			

 

				users = [
				  {'login': 'ilebedev', 'email': 'melevir@python.ru'},
				  {'login': 'kazauwa', 'email': 'kylehydeme@gmail.com'},
				]
				 
				for user_num in range(len(users)):
				  print(user_num, users[user_num]['email'])
			

 

				users = [
				  {'login': 'ilebedev', 'email': 'melevir@python.ru'},
				  {'login': 'kazauwa', 'email': 'kylehydeme@gmail.com'},
				]
				 
				for user in users:
				  print(user_num, user['email'])
			

 

				users = [
				  {'login': 'ilebedev', 'email': 'melevir@python.ru'},
				  {'login': 'kazauwa', 'email': 'kylehydeme@gmail.com'},
				]
				 
				for user in users:
				  print(user_num, user['email'])
			

 

				users = [
				  {'login': 'ilebedev', 'email': 'melevir@python.ru'},
				  {'login': 'kazauwa', 'email': 'kylehydeme@gmail.com'},
				]
				 
				for user_num, user in enumerate(users):
				  print(user_num, user['email'])
			

Итерация по индексам – зло

				users = [
				  {'login': 'ilebedev', 'email': 'melevir@python.ru'},
				  {'login': 'kazauwa', 'email': 'kylehydeme@gmail.com'},
				]
				 
				for user_num, user in enumerate(users):
				  print(user_num, user['email'])
			

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[2:7]
			[2, 3, 4, 5, 6]
			>>> a[2:7:2]
			[2, 4, 6]
			>>> a[0:3]
			[0, 1, 2]
			>>> a[6:10]
			[6, 7, 8, 9]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[2:7]
			[2, 3, 4, 5, 6]
			>>> a[2:7:2]
			[2, 4, 6]
			>>> a[0:3]
			[0, 1, 2]
			>>> a[6:10]
			[6, 7, 8, 9]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[2:7]
			[2, 3, 4, 5, 6]
			>>> a[2:7:2]
			[2, 4, 6]
			>>> a[:3]
			[0, 1, 2]
			>>> a[6:]
			[6, 7, 8, 9]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[:100]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[:100]
			[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[:]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[:]
			[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[::2]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[::2]
			[0, 2, 4, 6, 8]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[::-1]
		

Срезы

			>>> a = range(10)  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
			>>> a[::-1]
			[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
		

Срезы

			>>> 'omg, this works on strings!'[::-1]
			'!sgnirts no skrow siht ,gmo'
		

Всё