- 浏览: 2557424 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Learn to Program(1)
0. Getting Started
1. Numbers
1.1 Introduction to puts
puts simply writes onto the screen whatever comes after it.
1.2 Integer and Float
numbers without decimal points are called integers, and nunbers with decimal points are usually called floating-point numbers(floats).
1.3 Simple Arithmetic
addition + subtraction - multiplication * division /
2. Letters
2.1 String Arithmetic
puts 'I like' + 'applie pic.' #add string
puts 'blink ' * 4 #multiply string
7*3 really just means 7 + 7 + 7, so 'blink ' * 3 just means 'blink ' + 'blink ' + 'blink '
2.2 12 vs '12'
12 is a number, '12' is a string of two digits.
2.3 Problems
puts '12' + 12
puts '2' * '5'
error message: : can't convert Fixnum into String (TypeError)
And 'pig' * 5 is ok, but 5 * 'pig' is silly.
puts 'You're well!' =====> puts 'You\'re well!'
3. Variables and Assignment
Using vairables
str = '...you can say hello...'
puts str
puts str
We can assign an object to a variable, we can reassgin a different object to that variable.
var = 'just go go go'
puts var
var = 5 * (1 + 2)
puts var
In fact, variables can point to just about anything... except other variables.
var1 = 8
var2 = var1
puts var1
puts var2
var1 = 'eight'
puts var1
puts var2
And the result is:
8 8 eight 8
4. Mixing It Up
4.1 Conversions
Using .to_s to get the string version of an object.
puts 2.to_s + '5'
Using to_i gieves the integer version of an object, to_f gives the float version.
puts 2 + '5'.to_i
puts 99.99.to_i
puts '5 is a number'.to_f
puts 'number 5 is here'.to_i
and the result is 99, 5, 0
4.2 Another Look at Puts
Before puts tries to write out an object, it uses to_s to get the string version of that object. In fact, the s in puts stands for string.
4.3 The Methods gets and chomp
gets just sits there, reading what you type until you press Enter.
puts gets
puts gets.chomp
chomp takes off any Enters hanging out at the end of your string.
5. More About Methods
Every verb needs a noun, so every method needs an object.
If I say puts ' something', what I am really saying is self.puts ' something'.
5.1 Fancy String Methods
string method reverse which gives a backwards version of a string.
var1 = 'stop'
var2 = 'love'
puts var1.reverse
puts var2.reverse
Its results are pots, evol, it is really stange to see the string reverse.
var = 'carl'
puts 'the length of string carl is ' + var.length.to_s
upcase changes every lowercase letter to uppercase.
downcase changes every uppercase letter to lowercase.
swapcase switches the case of every leter in the string
capitalize is just like downcase, except that it switches the first character to uppercase.
var = 'caRl'
puts var.upcase
puts var.downcase
puts var.swapcase
puts var.capitalize
center adds spaces to the beginning and end of the string to make it cenered.
lineWidth = 50
puts('carl is a good guy'.center(lineWidth))
ljust and rjust, which stand for left justify and right justify. They are similar to center.
5.2 Higher Math
% puts 7%3 shows 1
abs, it just takes the absolute value of the number.
puts((-3).abs)
5.3 Random Numbers
The method to get a randomly chosen number is rand.
puts rand
puts rand
puts rand(100)
puts rand(100)
Note that I used rand(101) to get back numbers from 0 to 100, and that rand(1) always gives back 0.
Not understanding the range of possible return values is the biggest mistake.
srand ---> seed and rand
5.4 The Math Object
puts(Math::PI)
puts(Math.sqrt(4))
results: 3.14...., 2.0
references:
http://pine.fm/LearnToProgram/?Chapter=00
0. Getting Started
1. Numbers
1.1 Introduction to puts
puts simply writes onto the screen whatever comes after it.
1.2 Integer and Float
numbers without decimal points are called integers, and nunbers with decimal points are usually called floating-point numbers(floats).
1.3 Simple Arithmetic
addition + subtraction - multiplication * division /
2. Letters
2.1 String Arithmetic
puts 'I like' + 'applie pic.' #add string
puts 'blink ' * 4 #multiply string
7*3 really just means 7 + 7 + 7, so 'blink ' * 3 just means 'blink ' + 'blink ' + 'blink '
2.2 12 vs '12'
12 is a number, '12' is a string of two digits.
2.3 Problems
puts '12' + 12
puts '2' * '5'
error message: : can't convert Fixnum into String (TypeError)
And 'pig' * 5 is ok, but 5 * 'pig' is silly.
puts 'You're well!' =====> puts 'You\'re well!'
3. Variables and Assignment
Using vairables
str = '...you can say hello...'
puts str
puts str
We can assign an object to a variable, we can reassgin a different object to that variable.
var = 'just go go go'
puts var
var = 5 * (1 + 2)
puts var
In fact, variables can point to just about anything... except other variables.
var1 = 8
var2 = var1
puts var1
puts var2
var1 = 'eight'
puts var1
puts var2
And the result is:
8 8 eight 8
4. Mixing It Up
4.1 Conversions
Using .to_s to get the string version of an object.
puts 2.to_s + '5'
Using to_i gieves the integer version of an object, to_f gives the float version.
puts 2 + '5'.to_i
puts 99.99.to_i
puts '5 is a number'.to_f
puts 'number 5 is here'.to_i
and the result is 99, 5, 0
4.2 Another Look at Puts
Before puts tries to write out an object, it uses to_s to get the string version of that object. In fact, the s in puts stands for string.
4.3 The Methods gets and chomp
gets just sits there, reading what you type until you press Enter.
puts gets
puts gets.chomp
chomp takes off any Enters hanging out at the end of your string.
5. More About Methods
Every verb needs a noun, so every method needs an object.
If I say puts ' something', what I am really saying is self.puts ' something'.
5.1 Fancy String Methods
string method reverse which gives a backwards version of a string.
var1 = 'stop'
var2 = 'love'
puts var1.reverse
puts var2.reverse
Its results are pots, evol, it is really stange to see the string reverse.
var = 'carl'
puts 'the length of string carl is ' + var.length.to_s
upcase changes every lowercase letter to uppercase.
downcase changes every uppercase letter to lowercase.
swapcase switches the case of every leter in the string
capitalize is just like downcase, except that it switches the first character to uppercase.
var = 'caRl'
puts var.upcase
puts var.downcase
puts var.swapcase
puts var.capitalize
center adds spaces to the beginning and end of the string to make it cenered.
lineWidth = 50
puts('carl is a good guy'.center(lineWidth))
ljust and rjust, which stand for left justify and right justify. They are similar to center.
5.2 Higher Math
% puts 7%3 shows 1
abs, it just takes the absolute value of the number.
puts((-3).abs)
5.3 Random Numbers
The method to get a randomly chosen number is rand.
puts rand
puts rand
puts rand(100)
puts rand(100)
Note that I used rand(101) to get back numbers from 0 to 100, and that rand(1) always gives back 0.
Not understanding the range of possible return values is the biggest mistake.
srand ---> seed and rand
5.4 The Math Object
puts(Math::PI)
puts(Math.sqrt(4))
results: 3.14...., 2.0
references:
http://pine.fm/LearnToProgram/?Chapter=00
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 482NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 341Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 441Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 391Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 482NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 428Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 340Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 252GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 454GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 330GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 316Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 323Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 298Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 314Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 295NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 264Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 577NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 271Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 381Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 380Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
Learn to Program with Python 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者...
Learn to Program with Python:Take your first steps in programming and learn the powerful Python programming language,高清文字版
《Learn to Program》是一本专为初学者设计的编程教程,旨在帮助读者掌握编程基础知识,以英文版的形式呈现,让全球的学习者都能接触到这一宝贵的资源。在这个数字化的时代,编程技能已经成为一项重要的技能,不论是...
### 学习C++编程:McGraw-Hill出版社的《Learn To Program With C++》概览 #### 书籍背景与概述 《Learn To Program With C++》是McGraw-Hill出版社出版的一本关于C++编程的学习指南。这本书旨在为初学者提供一个...
https://www.amazon.cn/dp/148421868X/ref=sr_1_1?ie=UTF8&qid=1524202763&sr=8-1&keywords=learn+to+program+with+python 亚马逊上468原价的书,高清英文原版。
《Learn to Program with Small Basic》是一本专门针对儿童和少年编程教学的书籍,由Majed Marji和Ed Price编写,通过微软出品的Small Basic编程语言教授编程知识。该书旨在为初学者提供一种易于学习的编程方式,使...
Introduction to Programming_ Learn to program with Data StructuresIntroduction to Programming_ Learn to program with Data StructuresIntroduction to Programming_ Learn to program with Data ...
In Learn to Program with Scratch, author Majed Marji uses Scratch to explain the concepts essential to solvin g real-world programming problems. The labeled, color-coded blocks plainly show
1. **寓教于乐的学习方法**:本书通过Minecraft游戏环境教授编程知识,让读者在享受游戏乐趣的同时学习编程。 2. **即时反馈**:读者可以在Minecraft中看到自己的代码产生的效果,这种即时反馈极大地增强了学习体验...
Learn to Program with C teaches computer programming to the complete beginner using the native C language. As such, it assumes you have no knowledge whatsoever about programming. The main goal of this...