Giter Site home page Giter Site logo

sumonst21 / python-basics Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 9 KB

An introduction to the basic concepts of Python. Learn how to use Python both interactively and through a script. Create your first variables and acquaint yourself with Python's basic data types.

Python 100.00%

python-basics's Introduction

python-basics

When to use Python?

Python is a pretty versatile language. For which applications can you use Python?

Possible Answers
  • You want to do some quick calculations.
  • For your new business, you want to develop a database-driven website.
  • Your boss asks you to clean and analyze the results of the latest satisfaction survey.
  • All of the above.

The Python Interface

Example code added on script.py

Python Indentations

"""Where in other programming languages the indentation in code is for readability only, in Python the indentation is very important. Python uses indentation to indicate a block of code. """

Any comments?

To add comments to your Python script, you can use the # tag. These comments are not run as Python code, so they will not influence your result.

Python as a calculator

Python is perfectly suited to do basic calculations. Apart from addition, subtraction, multiplication and division, there is also support for more advanced operations such as:

  • Exponentiation: . This operator raises the number to its left to the power of the number to its right. For example 42 will give 16.
  • Modulo: %. This operator returns the remainder of the division of the number to the left by the number on its right. For example 18 % 7 equals 4.

The code in the script on the right gives some examples.

 Suppose you have $100, which you can invest with a 10% return each year. After one year, it's 100×1.1=110 dollars, and after two years it's 100×1.1×1.1=121. Add code on the right to calculate how much money you end up with after 7 years.

Variables & Types

Python is completely object oriented, and not "statically typed". You do not need to declare variables before using them, or declare their type. Every variable in Python is an object.

[This tutorial will go over a few basic types of variables] (https://www.learnpython.org/en/Variables_and_Types).

Other variable types

In the previous exercise, you worked with two Python data types:

  • int, or integer: a number without a fractional part. savings, with the value 100, is an example of an integer.
  • float, or floating point: a number that has both an integer and fractional part, separated by a point. factor, with the value 1.10, is an example of a float.

Next to numerical data types, there are two other very common data types:

  • str, or string: a type to represent text. You can use single or double quotes to build a string.
  • bool, or boolean: a type to represent logical values. Can only be True or False (the capitalization is important!).

Operations with other types

Filip mentioned that different types behave differently in Python.

When you sum two strings, for example, you'll get different behavior than when you sum two integers or two booleans.

python-basics's People

Contributors

sumonst21 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.