Загрузка...

Python: Chapter 1 Basics of Python (Working Environment, Variables, String, Whitespaces and Tabs)

Course Title: Python and Data Science Module 1: PYTHON CRASH COURSE By ERIC MATTHES Why python? Top reasons to learn python • Python is used in Data Science • Python’s scripting & automation • Python used with Big Data • Python supports Testing • Computer Graphics in Python • Python used in Artificial Intelligence • Python in Web Development • Python is portable & extensible • Python is simple & easy to learn What we will learn? Chapter 1: • Setting up your programming environment o Anaconda o Sublime Text o VS code o Atom o Pycharm etc. • Variables, Strings, Numbers and floats • String functions • String concatenation • How to add whitespaces and tabs • How to remove whitespaces and tabs • How to write comments Why anaconda Anaconda is popular because it brings many of the tools used in data science and machine learning with just one install, so it's great for having short and simple setup. Variables Let’s try using a variable in hello_world.py. Add a new line at the beginning of the file, and modify the second line: message = "Hello Python world!" print(message) Naming Variables • Variable names can contain only letters, numbers, and underscores. They can start with a letter or an underscore, but not with a number. • Spaces are not allowed in variable names, but underscores can be used. • Avoid using Python keywords and function names as variable names. • Variable names should be short but descriptive. Strings: A string is simply a series of characters. "This is a string." 'This is also a string.' This flexibility allows you to use quotes and apostrophes within your strings: 'I told my friend, "Python is my favorite language!"' Consider piece of code: name = "ada lovelace" print(name.title()) print(name.upper()) print(name.lower()) How to concatenate String: first_name = "ada" last_name = "lovelace" full_name = first_name + " " + last_name print(full_name) To add whitespace and Tabs use /t and /n print("\tPython") print("Languages:\n\tPython\n\tC\n\tJavaScript") Stripping whitespace, Strip() is used Understand code below: favorite_language = ' python ' favorite_language.rstrip() favorite_language.lstrip() favorite_language.strip() Integer and floats You can add (+), subtract (-), multiply (*), and divide (/) integers in Python Age= 23 Age = 23.5 age = 23 message = "Happy " + str(age) + "rd Birthday!" print(message) How Do You Write Comments? In Python, the hash mark (#) indicates a comment Exercise: 1. Find a quote from a famous person you admire. Print the quote and the name and age of its author. Make sure to use comments. Your output should look something like the following, including the quotation marks: Albert Einstein aged 43 years once said, “A person who never made a mistake never tried anything new.”

Видео Python: Chapter 1 Basics of Python (Working Environment, Variables, String, Whitespaces and Tabs) автора Python в деталях
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки