1. Trang chủ
  2. » Tất cả

PYTHON BASICS AND c CODING EXAMPLES: PROGRAMMING FOR BEGINNERS

80 2 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 80
Dung lượng 589,83 KB

Nội dung

PYTHON BASICS AND C CODING EXAMPLES PROGRAMMING FOR BEGINNERS PYTHON BASICS AND C CODING EXAMPLES PROGRAMMING FOR BEGINNERS J KING PYTHON INTRODUCTION PYTHON HISTORY AND VERSIONS FIRST PYTHON PROGRA. Python (phát âm tiếng Anh: ˈpaɪθɑːn) là một ngôn ngữ lập trình bậc cao cho các mục đích lập trình đa năng, do Guido van Rossum tạo ra và lần đầu ra mắt vào năm 1991. Python được thiết kế với ưu điểm mạnh là dễ đọc, dễ học và dễ nhớ. Python là ngôn ngữ có hình thức rất sáng sủa, cấu trúc rõ ràng, thuận tiện cho người mới học lập trình và là ngôn ngữ lập trình dễ học; được dùng rộng rãi trong phát triển trí tuệ nhân tạo. Cấu trúc của Python còn cho phép người sử dụng viết mã lệnh với số lần gõ phím tối thiểu.25 Vào tháng 7 năm 2018, van Rossum đã từ chức lãnh đạo trong cộng đồng ngôn ngữ Python sau 30 năm làm việc.2627 Python hoàn toàn tạo kiểu động và dùng cơ chế cấp phát bộ nhớ tự động; do vậy nó tương tự như Perl, Ruby, Scheme, Smalltalk, và Tcl. Python được phát triển trong một dự án mã mở, do tổ chức phi lợi nhuận Python Software Foundation quản lý.28

PYTHON BASICS AND C# CODING EXAMPLES PROGRAMMING FOR BEGINNERS J KING PYTHON INTRODUCTION PYTHON HISTORY AND VERSIONS FIRST PYTHON PROGRAM PYTHON VARIABLES PYTHON DATA TYPES PYTHON KEYWORDS PYTHON LITERALS PYTHON OPERATORS PYTHON COMMENTS PYTHON IF-ELSE STATEMENTS PYTHON LOOPS PYTHON FOR LOOP PYTHON WHILE LOOP PYTHON BREAK STATEMENT PYTHON CONTINUE STATEMENT PYTHON STRING PYTHON TUPLE C# | PRINT MESSAGES/TEXT (PROGRAM TO PRINT HELLO WORLD) C# PROGRAM TO PRINT A NEW LINE C# PROGRAM TO PRINT SIZE OF VARIOUS DATA TYPES TYPE CONVERSION FROM DOUBLE TO INT IN C# PROGRAM DEFINE VARIOUS TYPES OF CONSTANTS C# PROGRAM TO DEMONSTRATE EXAMPLE OF ARITHMETIC OPERATORS PROGRAM TO DEMONSTRATE EXAMPLE OF BITWISE OPERATORS PROGRAM TO DEMONSTRATE EXAMPLE OF RELATIONAL OPERATORS FIND THE ADDITION OF TWO INTEGER NUMBERS PROGRAM TO SWAP TWO NUMBERS PROGRAM TO DEMONSTRATE EXAMPLE OF SIMPLE IF ELSE STATEMENT EXAMPLE OF MULTIPLE IF ELSE STATEMENT C# PROGRAM OF CONDITIONAL OPERATOR C# PROGRAM EXAMPLE OF SWITCH STATEMENT C# PROGRAM TO FIND LARGEST OF TWO NUMBERS PRINT NUMBERS FROM TO 15 USING WHILE LOOP PRINT NUMBERS FROM TO 15 USING DO WHILE LOOP PROGRAM TO FIND OUT THE PRIME NUMBERS AMONG TO 30 PYTHON BASICS PROGRAMMING FOR BEGINNERS J KING PYTHON INTRODUCTION Python is a programming language that is general purpose, dynamic , high level, and interpreted To develop applications, it supports Object-Oriented programming approach Learning is simple and easy, and provides lots of high-level data structures Python is yet a powerful and versatile scripting language that is easy to learn, making it attractive for application development With its interpreted nature, Python's syntax and dynamic typing make it an ideal language for scripting and quick application development Python supports multiple styles of programming including object-oriented, imperative, and functional or procedural styles Python is not intended to operate in a given area, such as web programming This is why it is known as the language of multipurpose programming because it can be used with web, enterprise, 3D CAD etc We don't have to use data types to declare variable because it's typed dynamically so that we can write a=10 to assign an integer value in an integer variable Python Features Python makes the development and debugging fast because the compilation step is not included in the development of Python, and the edit-test-debug cycle is very fast Compared with other programming languages Python is easy to learn Its syntax is direct and much the same as the English language The semicolon or curly-bracket is not used, and the indentation defines the block of code It is the recommended language for beginners in the programming Using a few lines of code Python can perform complex tasks A simple example, you simply type print("Hello World”) to the hello world program It'll take one line to execute, while Java or C will take multiple lines Python History and Versions Guido Van Rossum at CWI in The Netherlands began implementing Python in December 1989 Guido Van Rossum published the code (labeled version 0.9.0) to alt.sources in February 1991 Python 1.0 was released in 1994, with new features such as lambda, map, filter, and reduce Python 2.0 has added new features such as list understandings and garbage collection systems Python 3.0 (also called "Py3 K") was released on December 3, 2008 It had been designed to correct the language's fundamental flaw Python Version List Python Version Released Date Python 1.0 January 1994 Python 1.5 December 31, 1997 Python 1.6 September 5, 2000 Python 2.0 October 16, 2000 Python 2.1 April 17, 2001 Python 2.2 December 21, 2001 Python 2.3 July 29, 2003 Python 2.4 November 30, 2004 Python 2.5 September 19, 2006 Python 2.6 October 1, 2008 Python 2.7 July 3, 2010 Python 3.0 December 3, 2008 Python 3.1 June 27, 2009 Python 3.2 February 20, 2011 Python 3.3 September 29, 2012 Python 3.4 March 16, 2014 Python 3.5 September 13, 2015 Python 3.6 December 23, 2016 Python 3.7 June 27, 2018 Python 3.8 October 14, 2019 To download the latest Python release, please visit the link https:/www.python.org/downloads/ First Python Program In this section, we 're going to discuss Python 's basic syntax, and run a simple program to print Hello World on the console Python provides us with two modes of running a program: Using Interactive interpreter prompt Using a script file Interactive interpreter prompt Python gives us the functionality to execute the Python statement at the interactive prompt one by one In the case where we are concerned about the output of every line of our Python programme Open the terminal (or command prompt) and type python (python3, if you have both Python2 and Python3 installed on your system) It will open the following prompt where we can execute the statement in Python and check its impact on the console Using a script file The interpreters prompt is good at running the individual code statements We can't write the code on the terminal anytime Our code must be written into a file that can be executed later To this, open a notepad editor, create a file named first.py (Python used the.py extension) and write the following code into it print ("hello world"); #here, we have used print() function to print the message on the console Run the following command on the terminal $ python3 first.py Python Variables Variable is a name used to refer to the location of a memory Also known as an identifier and used for holding value In Python, we don't need to specify the variable type, because Python is an inferior language and is smart enough to get the type of variable Variable names can be a group of letters and digits, but must start with a letter or an underscore Using lowercase letters for name of the variable is recommended Rahul and rahul are both two different variables Identifier Naming Variables - example of identifiers To identify the literals used in the program an Identifier is used The rules for naming an identifier are set out below The variable must have an alphabet or underscore (_) as its first character All characters except the first character can be lower-case(a-z), upper-case (A-Z), underscore, or digit (0-9) alphabets The name of the identifier shall not contain any white space or any special character!, (@,#,%,^, &, *) The name of the identifier must not be similar to any keyword set in the language Identifier names are case sensitive; my name, for example, and MyName is not identical Declaring Variable and Assigning Values Python does not bind us to declare a variable before we use it in the app It enables us to create a variable in the time required In Python we not need to declare explicitly variable That variable is declared automatically when we assign any value to the variable The operator equal (=) is used to assign value to a variable Object References When we declare a variable it's necessary to understand how the Python interpreter works The process of treating variables differs slightly from many other programming languages Python is a highly object-oriented programming language; therefore, each data item belongs to a specific class type Consider example below print("John") OUTPUT John The object in Python creates an integer and displays it to the console We created a string object in the preceding print statement Let's check its type using the built-in type() function in Python type("John") OUTPUT Object Identity In Python, each object created uniquely identifies with Python Python ensures no two objects will have the same identifier The Id() function built-in is used to identify the identifier of the object Consider example below a = 50 b=a print(id(a)) print(id(b)) .. .PYTHON BASICS AND C# CODING EXAMPLES PROGRAMMING FOR BEGINNERS J KING PYTHON INTRODUCTION PYTHON HISTORY AND VERSIONS FIRST PYTHON PROGRAM PYTHON VARIABLES PYTHON DATA TYPES PYTHON KEYWORDS PYTHON. .. LITERALS PYTHON OPERATORS PYTHON COMMENTS PYTHON IF-ELSE STATEMENTS PYTHON LOOPS PYTHON FOR LOOP PYTHON WHILE LOOP PYTHON BREAK STATEMENT PYTHON CONTINUE STATEMENT PYTHON STRING PYTHON TUPLE C# |... TO 30 PYTHON BASICS PROGRAMMING FOR BEGINNERS J KING PYTHON INTRODUCTION Python is a programming language that is general purpose, dynamic , high level, and interpreted To develop applications,

Ngày đăng: 27/11/2022, 21:29