The power Shell's variables, arrays, objects, and operators are detailed

Source: Internet
Author: User
Tags arrays numeric

"Variables and Constants"

Variable: The amount that will change, temporarily storing the data so that you can call it later

Constants: Quantity that does not change

One, variable and array

"Variable", like in memory to divide a space, you can store some data, can only store a pair of

A line corresponding to an object

"Arrays", like dividing multiple storage spaces in memory, containing subscripts, can hold data from multiple objects

(1), using variable

A variable (Variable) is a memory cell in which a value is stored, and in PowerShell, the variable is represented by a single word literal string that begins with the symbol $

1, the creation and modification of variables

Format:$< variable name >=< variable value >

"The characteristics of the variable"

You do not have to declare variable types in PowerShell, you can be integers, floating-point numbers, characters, strings, arrays, and so on. For example: $sum =1; $sum =1.5; $arry = "abc", "EFG"

Variables can be created and used directly within the console

2, display the value of the variable

Enter the name of the variable in the console (beginning with $)

Use get-variable to view variables (get-variable variable names)

3, the operation of the variable

Calculate the radius of a circle

Output calculation results

"As shown above, the steps to create a variable and perform a mathematical operation"

1 Create variable $pi and assign a value of 3.1416

2) Prompts the user to enter the radius of the circle, enter a value of 12

Read-host receives user input, the stored value type is a character type (String), the numeric calculation must be converted to a numeric type, and "decimal" means that the variable is cast from character to Decimal, and decimal is a cast numeric type, representing "decimal"

3 Calculate the area of the circle with the radius of the input

The calculation formula of the circle is: area=pi* (r*r), in PowerShell, the square can be multiplied by two numbers, $r receive the user input value, the variable $area is the area of the circle, * is the multiplication operator of the PowerShell, $area = $pi * ($R * $R). () represents precedence in multiplication operations

Highest level

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.