Hiển thị các bài đăng có nhãn Python 3. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Python 3. Hiển thị tất cả bài đăng

Thứ Tư, 28 tháng 9, 2016

Python 3 Tutorial : IF ELIF ELSE Conditionals Statements in Python 3


Python 3 Tutorial - In python 3 languages, else statement can be combined with an if/elif statement. Else statement has mean the block of code that will executes if the conditional expression resolves to 0 or a FALSE value in the if statement or an function.

At the previews lessons, we have learn about python 3, please read :
  1. Basics Syntax in Python 3
  2. Create First Program with Python 3
  3. How to Install Python Tools for Visual Studio 2015
Next, we will learn how to use IF ELIF ELSE Conditionals Statements in Python 3, The else statement is an optional statement and there could be at most only one else statement following if syntax :

IF ELSE Statement

#!/usr/bin/python3
if expression:
   our statement(s)
else:
   our statement(s)

for more example using the if else statement in python 3

#!/usr/bin/python3
data = int(input("Enter any integer : "))
if data < 6000:
    price = data * 1.14
    print ("the price is ",price)
else:
    price = data * 2
    print ("the price is ",price)
print ("All Price is :",data - price)

try to debugging your application, then tell me what're you getting.

IF ELIF ELSE Conditionals Statements in Python 3

IF ELIF ELSE Statements

In python 3 language, elif statement will allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.

To try using if elif else statement, following this python syntax code :

if expression-1:
   our statement(s)
elif expression-2:
   our statement(s)
elif expression-3:
   our statement(s)
else:
   our statement(s)

for example

#!/usr/bin/python3
data = int(input("Enter any integer : "))
if data < 6000:
    price = data * 1.14
    print ("the price is ",price)
elif data < 3000:
    discount= data * 1
    print ("the price is ",price)
else:
    price = data * 2
    print ("the price is ",price)
print ("All Price is :",data - price)

if you still confused, or you use python 2, go to this page "Python 2 Tutorial".

see you next lessons ......

Thứ Ba, 27 tháng 9, 2016

Python 3 Tutorial : Basics Syntax in Python 3


Python 3 tutorial - in Python 3 or python 2, we has many similarities to C, and Java programming languages.

At the previews lessons, we have learn about python 3, please read
  1. How to install python tools for visual studio
  2. How to create "Hello World" program using python 3
in this lessons, we will Explain about Basics Syntax that can use in Python 3.

Start writing Code

As we know, to print simple string with python 3, just following this script

print ("Hello World!")

When you execute that file (helloworld.py) on your command or debugging from visual studio, you will get this result :

Hello World!

Lines and Indentation

To indicate an blocks of a code in the class in python 3, that doesn't use an braces({}). For this point, python 3 not same with other programming language, see code line below.

if True:
    print ("It's True statement")
else:
    print ("It's False statement")

Multi-Line Statements

Multi line Statements in Python 3  typically end with a new line. Python does, however, allow the use of the line continuation character (\) to denote that the line should continue.

Python 3 Tutorial : Basics Syntax in Python 3

data  = variable1 + \
        variable2 + \
        variable3

or, more example we can try use array in python 3

days  = ['Monday', 'Tuesday', 'Wednesday',
        'Thursday', 'Friday']

Quotation in Python

Python 3 programming language accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string.

just following this python simple code below :

word      = 'word'
sentence  = "This is a sentence."
paragraph = """This is a paragraph. It is
            made up of multiple lines and sentences."""

Comments in Python

To add comment in python 3 programming languages A hash sign (#) that is not inside a string literal begins a comment. All characters after the # and up to the end of the physical line are part of the comment and the Python interpreter ignores them.

#!/usr/bin/python3
# First comment
print ("Hello World!") # next comment
print ('let me introduce myself') # this, comment too,
# this comment to print ("My name is Harison, I work at an Private Company in Indonesia.")
print ("'CV.Delta Microtech' as a .Net Programmer since 2010.")
print ("Please Subscribe and Follow Our Social Medias 'Sector Code' to get Latest tutorials and will be send to your email everyday for free!,")
print ('Nice to meet you and Happy coding :) all ^^')

Multiple Statements on a Single Line

in python 3 programming language, The semicolon ( ; ) will allows for multiple statements on the single line given that neither statement starts a new code block. Here is a sample snip using the semicolon :

import sys; a = 'string'; sys.stdout.write(a + '\n')

Multiple Statement Groups as Suites

A group of individual statements, which make a single code block are called suites in Python. Compound or complex statements, such as if, while, def, and class require a header line and a suite.

Header lines begin the statement (with the keyword) and terminate with a colon ( : ) and are followed by one or more lines which make up the suite. For example, following this python code :

if expression : 
   suite
elif expression : 
   suite 
else : 
   suite

See you next Lessons..

Thứ Hai, 26 tháng 9, 2016

Python 3 Tutorial : Create First Program with Python 3


Python 3 tutorial - Print Hello world and create your first program using python 3 programming languages. at previews lessons, we have learned how to install python tools in visual studio, please read How to Install Python Tools for Visual Studio 2015.

Next, we will create your first simple console application made with python 3 language,

"Hello World!" Program in Python 3

First step, please open your visual studio and create new python project, File > New > Project > Python > Python Application > create python project name "FirstPythonApp" and ok.

Add python source code in the FirstPythonApp.py

#!/usr/bin/python3
print ("Hello World!")
print ('let me introduce myself')
print ("My name is Harison, I work at an Private Company in Indonesia.")
print ("'CV.Delta Microtech' as a .Net Programmer since 2010.")
print ("Please Subscribe and Follow Our Social Medias 'Sector Code' to get Latest tutorials and will be send to your email everyday for free!,")
print ('Nice to meet you and Happy coding :) all ^^')

Next, try to debugging your program with pres "F5" key.

Python 3 Tutorial : Create First Program with Python 3

Video tutorial Create First Program with Python 3


See you next lessons ...

Thứ Bảy, 24 tháng 9, 2016

Python 3 Tutorial : How to Install Python Tools for Visual Studio 2015


Python 3 Tutorial - What's new in Python 3? Python 3 version released in 2008. Python 3.0 version is supposed to be backward incompatibles, later on many of its important features have been backported to be compatible with version 2.7.

This tutorial gives enough understanding on Python 3 version and We can learn step by step how to code with Python programming language using visual studio 2015.

How to Install Python Tools for Visual Studio 2015

First step - you must have visual studio on your computer before, i'm using visual studio 2015 Enterprise version.
Open your visual studio, on the top menu click file > new project > Python Templates > Install Python Tools for Visual Studio > Install

Next, we were told to waiting installation / update session. Please wait until installation process is finished.

Mybe, after python tools for visual studio was installed, you need to restarting your system and open your visual studio again.

Video Tutorial How to Install Python Tools for Visual Studio 2015


See you next lessons ...